Parsing webhook responses when the status code is not 200

(This is somewhat related to this question)

Is there a way to parse responses to webhooks if the status code is not 200?

Right now, it appears that non-200 response status codes result in the webhook returning a string, like this

Response body: {"statusCode":400,"error":"invalid_grant","message":"Invalid refresh token"}
Request to external system failed and returned unsuccessful response code: 400

Instead, is there a way to get this JSON in a structured form:

{
  "statusCode": 400,
  "error":"invalid_grant",
  "message":"Invalid refresh token"
}

Directly with webhooks, unfortunately there is not, and for various reasons it would be complex to add this behavior in a reasonable way (though it’s something we’re looking into!)

The workaround here would be to use an external function (import a source into your function and call it directly instead of using a webhook), and you can customize the behavior on failure codes

2 Likes