pbs-middleware-server/src/main/java/com/pbs/middleware/server/common/exception/MiddlewareExceptionHandler.java
/**
     * All unhandled exception are returned as [com.pbs.middleware.server.common.exception.AccessDeniedException]
     */
All unhandled exception are returned as [com.pbs.middleware.server.common.exception.AccessDeniedException]
All unhandled exception are returned as [ com . pbs . middleware . server . common . exception . AccessDeniedException ]
@ExceptionHandler({org.springframework.security.access.AccessDeniedException.class})
    public ResponseEntity<Object> handleAccessDeniedException(Exception ex) {
        if (ex.getMessage().toLowerCase().contains("access is denied")) {
            return new ResponseEntity<>("Unauthorized Access", new HttpHeaders(), HttpStatus.UNAUTHORIZED);
        }
        return new ResponseEntity<>(
                ErrorResponse.of(
                        Error.builder()
                                .code(INTERNAL_ERROR.toString())
                                .message(ex.getMessage())
                                .build()),
                INTERNAL_SERVER_ERROR);
    }
@ ExceptionHandler ( { org . springframework . security . access . AccessDeniedException . class } ) public ResponseEntity < Object > handleAccessDeniedException ( Exception ex ) { if ( ex . getMessage ( ) . toLowerCase ( ) . contains ( "access is denied" ) ) { return new ResponseEntity < > ( "Unauthorized Access" , new HttpHeaders ( ) , HttpStatus . UNAUTHORIZED ) ; } return new ResponseEntity < > ( ErrorResponse . of ( Error . builder ( ) . code ( INTERNAL_ERROR . toString ( ) ) . message ( ex . getMessage ( ) ) . build ( ) ) , INTERNAL_SERVER_ERROR ) ; }
All unhandled exception are returned as [com.pbs.middleware.server.common.exception.AccessDeniedException]
All unhandled exception are returned as [ com . pbs . middleware . server . common . exception . AccessDeniedException ]