[英]custom exception message in spring cloud function deployed in aws-lambda
I have a java project written using spring-cloud-function and deployed in aws-lambda.我有一个使用 spring-cloud-function 编写并部署在 aws-lambda 中的 java 项目。
I am trying to return a custom exception with some fields in the exception message body, something like"我正在尝试返回一个自定义异常,其中包含异常消息正文中的某些字段,例如“
{
reason: <exception reason>
code: <error code>
<some other fields>
}
@ExceptionHandler, that is generally used in spring boot doesn't seem to work here. @ExceptionHandler,一般在spring boot中使用的,在这里似乎不起作用。
I can return the exception in the required format by creating a class for building the exception message in required format but in that case the error code will always be 200 since it will not be an exception object per se.我可以通过创建 class 以所需格式构建异常消息来返回所需格式的异常,但在这种情况下,错误代码将始终为 200,因为它本身不会是异常 object。 Instead it will be my custom error object.
相反,它将是我的自定义错误 object。
Is there a way I can set this up so that the above required format of exception object is returned and correct error code can be returned too?有没有一种方法可以设置它以便返回上述异常 object 所需的格式并且也可以返回正确的错误代码?
Thanks in advance提前致谢
First, the exception has nothing to do with Spring Boot.首先,异常与Spring Boot无关。 It's part of spring-web, so yes it would not work here since sc-function is a general purpose framework, where the same function could be deployed and triggered via web, streaming, aws-lambda etc. .
它是 spring-web 的一部分,所以是的,它在这里不起作用,因为 sc-function 是一个通用框架,可以通过 web、流、aws-lambda 等部署和触发相同的 function。
Now, yes we had a problem returning JSON error (as you show) or object that represents the same, but that was fixed.现在,是的,我们在返回 JSON 错误(如您所示)或表示相同错误的 object 时遇到问题,但已修复。 So please update sc-function to 3.2.3.
所以请更新 sc-function 到 3.2.3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.