Appsync与Go Lambda解析器的错误处理

huangapple go评论78阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2022年9月6日 15:31:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/73618270.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定