I'm trying to implement custom response message using this code:
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException ex) throws IOException {
ErrorDetail errorDetail = ErrorDetail.NOT_FOUND;
ErrorResponse errorEntry = new ErrorResponse();
errorEntry.setTitle(errorDetail.getTitle());
errorEntry.setCode(errorDetail.getErrorCode());
HttpStatus httpStatus = ErrorDetail.getHttpStatusBasedOnErrorCode(errorDetail.getErrorCode());
errorEntry.setStatus(httpStatus.value());
errorEntry.setDetail(ex.getMessage());
Map<String, String> extra = new HashMap<String, String>();
extra.put("detail", ex.getMessage());
errorEntry.setExtra(extra);
ErrorResponseDTO errorResponse = new ErrorResponseDTO();
errorResponse.setErrors(Arrays.asList(errorEntry));
response.setStatus(errorDetail.getHttpStatus().value());
String json = new ObjectMapper().writeValueAsString(errorResponse);
response.getWriter().write(json);
response.flushBuffer();
}
}
I get this response:
{
"errors": [
{
"status": 404,
"code": "1000",
"title": "Title not found",
"detail": "Full authentication is required to access this resource",
"source": null,
"debugDetail": null,
"extra": {
"detail": "Full authentication is required to access this resource"
}
}
]
}
I can't find why I get the values:
"source": null,
"debugDetail": null,
I don't set these values anywhere. Do you know how I can remove them?
Full Github code: