Skip to content

Wrong return http #37981

Closed as not planned
Closed as not planned
@kratess

Description

@kratess

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions