sanger96 / Happenings_Team-5_UTD_Senior_Design_Project

UTD Senior Design Project; Group Members: Gaurav Sanger, Jonathan Lam, Robert Dohm, Landin Kasti, Charles Eaton
3 stars 0 forks source link

Research way to return custom JSON error messages from methods #86

Open LKASTI opened 3 months ago

LKASTI commented 3 months ago

We need a way to return custom JSON error messages from methods without changing their return type. This should be help the frontend identify errors like appointment conflicts.

LKASTI commented 3 months ago

Researching how to accomplish this through the following resources:

https://www.baeldung.com/spring-response-entity https://www.baeldung.com/exception-handling-for-rest-with-spring https://www.baeldung.com/global-error-handler-in-a-spring-rest-api

LKASTI commented 3 months ago

This seems like a good way to handle exceptions: https://www.baeldung.com/spring-response-status-exception.

For example, we create a custom exception class that inherits from Exception. Then we can run try catch blocks in the service and controller to return a detailed exception similar to this:

Image

jonathan-jlam commented 3 months ago

I looked into something like this, but the only concern I have is that throwing an exception might halt the execution of any code that may come after. For example, in the PageScraper, if the processing of one event throws an exception, I believe the whole scraping process stops. I am not sure if the PageScraper would ever cause an exception to be thrown though.

jonathan-jlam commented 3 months ago

Now that I think about it, though, I suppose we could just modify the PageScraper to also catch the [Entity]NotFound exception as well.