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

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

问题描述

我使用 Jackson/JSON 设置了 Spring REST,一切正常.

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

但我故意在消息结构中引入了一个错误,导致 400 - 错误请求.但是服务器上没有日志输出.我所期望的错误类似于Jackson 未知属性异常"之类的东西,但它被捕获并向客户端发送了 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);
}

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

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