Closed as not planned
Description
I am woring with Spring boot and jpa to manage connection to postgresql database.
This is what i use for general exception purpose.
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class GeneralExceptionHandler extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity<Object> createResponseEntity(Object body, HttpHeaders headers, HttpStatusCode statusCode,
WebRequest request) {
HttpStatus httpStatus = HttpStatus.resolve(statusCode.value());
if (httpStatus == null) return ResponseHandler.generateErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseHandler.generateErrorResponse(httpStatus, ((ProblemDetail) body).getDetail());
}
}
public static ResponseEntity<Object> generateErrorResponse(@NotNull HttpStatus status, String message) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("error", status.getReasonPhrase());
map.put("message", message);
map.put("status", status.value());
return new ResponseEntity<Object>(map, status);
}
body = ProblemDetail[type='about:blank', title='Internal Server Error', status=500, detail='Failed to write request', instance='null', properties='null']
i get this response
{
"data"
}{
"error": "Internal Server Error",
"message": "Failed to write request",
"status": 500
}
as you can clearly see with "data"}{ in plus