简体   繁体   English

spring 中的自定义异常消息 云 function 部署在 aws-lambda

[英]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.

相关问题 Spring Cloud Function on AWS Lambda Platform 全局异常处理 - Global Exception Handling in Spring Cloud Function on AWS Lambda Platform Aws-Lambda 导出默认功能不起作用 - Aws-Lambda export default function does not work 从 Spring 云访问 AWS Lambda 上下文 Function - Accessing AWS Lambda Context from Spring Cloud Function aws-lambda 实例的唯一标识? - Unique id of aws-lambda instance? 无法授予 aws-lambda 对 aws-appsync API 的访问权限 - Cannot give aws-lambda access to aws-appsync API aws-lambda中使用APIGatewayProxyRequestEvent时如何获取日志的Context - How to get Context for logging when using APIGatewayProxyRequestEvent in aws-lambda 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 从 AWS Pinpoint 自定义通道向 AWS Lambda 发送消息 - Sending message to AWS Lambda from AWS Pinpoint Custom Channel 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 错误消息:“'NoneType' object 不可调用”。 - 从 zappa 收到在 AWS Lambda 上部署的 django 应用程序 - Error message: "'NoneType' object is not callable". - received from zappa deployed django application on AWS Lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM