Home >Backend Development >Golang >How to catch 410 error from `postToConnection` call via golang aws sdk?
I am using websocket apigateway in AWS to manage websocket connections. There are situations where the connection is disconnected but the @disconnect
route is not triggered. In this case, the postToConnection
api call will return a 410 error.
I am using golang sdk github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi
. postToConnection
API returned PostToConnectionOutput with error
. How to detect if an error is a 410 error?
You can check that the returned error is goneexception
type
See https://aws.github.io /aws-sdk-go-v2/docs/handling-errors/
import( api "github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi" apitypes "github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi/types" ) func main() { svc := api.New(api.Options{ Region: "your-region", }) output, err := svc.PostToConnection(ctx, &api.PostToConnectionInput{ ConnectionId: aws.String("your-connection-id"), }) if err != nil { var gne *apitypes.GoneException if errors.As(err, &gne) { log.Println("error:", gne.Error()) } return } }
The above is the detailed content of How to catch 410 error from `postToConnection` call via golang aws sdk?. For more information, please follow other related articles on the PHP Chinese website!