在AWS-LAMBDA中部署的Spring Cloud函数中的自定义异常消息

发布于 2025-01-23 20:46:30 字数 315 浏览 4 评论 0原文

我有一个使用Spring-Cloud功能编写的Java项目,并在AWS-Lambda中部署。

我正在尝试返回一个具有异常消息主体中某些字段的自

{
  reason: <exception reason>
  code: <error code>
  <some other fields>
}

定义

异常 因为它不是一个例外对象。

用于以必需的格式构建异常消息,但在这种情况下,错误代码将是200个, 异常对象的格式,并且可以返回正确的错误代码?

返回了上述

I have a java project written using spring-cloud-function and deployed in aws-lambda.

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.

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. Instead it will be my custom error 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?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2025-01-30 20:46:31

首先,例外与Spring Boot无关。它是Spring-Web的一部分,因此是的,在这里无法使用,因为SC功能是一个通用框架,可以通过Web,Streaming,Aws-Lambda等部署和触发相同的功能。

现在,是的,我们在返回JSON错误(如您所显示的)或代表相同的对象时遇到了问题,但已修复。因此,请将SC功能更新为3.2.3。

First, the exception has nothing to do with Spring Boot. It's part of spring-web, so yes it would not work here since s-c-function is a general purpose framework, where the same function could be deployed and triggered via web, streaming, aws-lambda etc. .

Now, yes we had a problem returning JSON error (as you show) or object that represents the same, but that was fixed. So please update s-c-function to 3.2.3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文