Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4797

Customize Global Exception Handler in java Spring Boot

$
0
0

My GlobalExceptionHandler

@ControllerAdvice("uz.pdp.warehouse")public class GlobalExceptionHandler {    @ExceptionHandler({RuntimeException.class})    public ResponseEntity<DataDto<AppError>> handle500(RuntimeException e, WebRequest webRequest) {        return new ResponseEntity<>(                new DataDto<>(AppErrorDto.builder()                        .message(e.getMessage())                        .status(HttpStatus.INTERNAL_SERVER_ERROR)                        .path(webRequest.getContextPath())                        .build()));    }}

I want to return my customized ResponseEntity but it returns something different

{"timestamp": "2022-03-27T06:21:00.845+00:00",`"status": 404,"error": "Not Found","trace": "uz.pdp.warehouse.exception.NotFoundException: QWE\r\n","message": "QWE","path": "/test/testN"}

then I also catch exception with try{}catch(){} it is working but I want to handle exception via my GlobalExceptionHandler.

Is it possible return customized AppError or ResponseEntity?


Viewing all articles
Browse latest Browse all 4797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>