I am using websocket apigateway in AWS to manage websocket connections. There are cases that the connection is disconnected but the @disconnect
route is not triggered. In this case, postToConnection
api call will return 410 error.
I am using golang sdk github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi
. The postToConnection
API returns PostToConnectionOutput, error
. How can I detect whether the error is 410 error?
2
Answers
You can check the returned error is a type of
GoneException
See https://aws.github.io/aws-sdk-go-v2/docs/handling-errors/
To detect whether the error returned from the postToConnection API is a 410 error, you can check the error type using a type assertion.
Here is an example:
In the above example, we first make the postToConnection API call and check the error returned by the API call. We then use a type assertion to check if the error is of type apigatewaymanagementapi.GoneException. If the error is a GoneException, we can handle it appropriately, for example, by reconnecting or closing the connection.
If the error is not a GoneException, we can handle it in some other way, for example, by logging the error or retrying the API call.