Remove values from access handler

时光总嘲笑我的痴心妄想 提交于 2020-06-17 09:58:00

问题


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:

来源:https://stackoverflow.com/questions/62311702/remove-values-from-access-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!