Commit c2da37f9 by Patryk Czarnik

ExceptionUtils i wypisywanie wszystkich błędów

parent 0f9ff0c1
......@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import sklep.model.Product;
import sklep.repository.ProductRepository;
import sklep.utils.ExceptionUtils;
@Controller
@RequestMapping("/products")
......@@ -94,7 +95,7 @@ public class ProductController {
productRepository.save(product);
model.addAttribute("saved", true);
} catch(Exception e) {
model.addAttribute("errors", List.of(e.toString()));
model.addAttribute("errors", ExceptionUtils.allMessages(e));
}
return "product_form";
}
......
package sklep.utils;
import java.util.ArrayList;
import java.util.List;
public class ExceptionUtils {
public static List<String> allMessages(Throwable e) {
List<String> messages = new ArrayList<>();
messages.add(oneMessage(e));
Throwable cause = e.getCause();
while(cause != null) {
messages.add(oneMessage(cause));
cause = cause.getCause();
}
return messages;
}
private static String oneMessage(Throwable e) {
return e.getClass().getSimpleName() + ": " + e.getMessage();
}
}
......@@ -60,7 +60,6 @@ h2, h3, h4 {
background-color: white;
font-weight: bold;
min-width: 500px;
max-width: 1000px;
}
#wyszukiwarka {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment