使用Jackson的Spring REST-400错误的请求记录 [英] Spring REST using Jackson - 400 bad request logging

查看:148
本文介绍了使用Jackson的Spring REST-400错误的请求记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Jackson/JSON设置了春季REST,并且一切正常.

I have spring REST set up fine using Jackson/JSON and everything works.

但是我故意在消息的结构中引入了一个错误,该错误导致了400-错误的请求.但是服务器上没有日志输出.我所期望的错误将是杰克逊未知属性异常"之类的东西,但它被捕获,并且向客户端发送了400错误,但服务器上没有该异常的日志.

But I knowingly introduced an error in the structure of the message which resulted in a 400 - Bad Request. But there was no log output on the server. The error I would be expecting would be something like "Jackson unknown property exception" or whatever but it was caught and a 400 error was sent to the client, but no log of the exception on the server.

我不想明确调试服务器上的所有内容,但我希望像这样的Spring网络级异常明确标记为错误.

I don't want to debug everything on the server clearly, but I want Spring network level exceptions like this clearly labelled as error.

打开此功能的正确方法是什么?

What is the correct way to switch this on?

谢谢!

推荐答案

@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public void handle(HttpMessageNotReadableException e) {
    logger.warn("Returning HTTP 400 Bad Request", e);
}

这篇关于使用Jackson的Spring REST-400错误的请求记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆