vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
921 stars 58 forks source link

Provide an application-wide convention for error handling #1320

Open tarekoraby opened 1 year ago

tarekoraby commented 1 year ago

Hilla already provides some error-handling mechanisms to catch errors occurring in the backend. However, for many use cases, having a global unified way to do error handling would be beneficial (at least one wouldn't have to repeat the same code in multiple endpoint methods).

Hilla should provide an application-wide convention for error handling, perhaps similar to Spring's @ExceptionHandler + @ControllerAdvice:

@ControllerAdvice
public class RestResponseEntityExceptionHandler 
  extends ResponseEntityExceptionHandler {

    @ExceptionHandler(value 
      = { IllegalArgumentException.class, IllegalStateException.class })
    protected ResponseEntity<Object> handleConflict(
      RuntimeException ex, WebRequest request) {
        String bodyOfResponse = "This should be application specific";
        return handleExceptionInternal(ex, bodyOfResponse, 
          new HttpHeaders(), HttpStatus.CONFLICT, request);
    }
}
knoobie commented 1 year ago

Just dropping this here to consider. https://datatracker.ietf.org/doc/rfc9457/