英文:
Appsync with go lambda resolver error handling
问题
我正在使用AppSync > Lambda解析器(使用golang)> DynamoDB。
我已经在各个地方寻找更多关于它们的错误处理的信息。首先,似乎AppSync不依赖于从lambda解析器返回的状态码来指示是否存在问题。相反,我们在lambda函数中返回一个错误。
例如:func(event CustomEventStruct) (map[string]any, error)
现在,如果我在这里返回一个错误,看起来我只能控制消息。AppSync还似乎至少有一个"errorType"。
是否有一种方法可以控制错误类型,可能是状态码(尽管从我所读的内容来看,我对此表示怀疑),以及错误消息?
英文:
I am using AppSync > Lambda resolver (using golang) > Dynamodb
I've looked everyone for more information on error handling with them. To start with, it appears as if AppSync doesn't rely on status codes coming back from the lambda resolver to indicate if there was an issue. Instead, we return an error in the lambda function
i.e. func(event CustomEventStruct) (map[string]any, error)
Now, if I return an error in this, it looks like I'm only able to control the message. AppSync also appears to have an "errorType" at the minimum.
Is there a way to control the error type, potentially a status code (though I doubt it from what I've read) and the errorMessage?
答案1
得分: 0
在进行一些调查后,我发现在这里有一个错误的结构体:
"github.com/aws/aws-lambda-go/lambda/messages"
这里有一个结构体:
//nolint:stylecheck
type InvokeResponse_Error struct {
Message string json:"errorMessage"
Type string json:"errorType"
StackTrace []*InvokeResponse_Error_StackFrame json:"stackTrace,omitempty"
ShouldExit bool json:"-"
}
它期望一个带有json:"errorType"
和json:"errorMessage"
标签的结构体来控制返回给AppSync的值。
英文:
After doing some digging, I found that there is an error struct located here:
"github.com/aws/aws-lambda-go/lambda/messages"
There is a struct:
//nolint:stylecheck
type InvokeResponse_Error struct {
Message string `json:"errorMessage"`
Type string `json:"errorType"`
StackTrace []*InvokeResponse_Error_StackFrame `json:"stackTrace,omitempty"`
ShouldExit bool `json:"-"`
}
It expects a struct with the json tags json:"errorType"
and json:"errorMessage"
to control the return values to AppSync.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论