Best answer

Adding After afterResponse error handing breaks authentication

  • 9 June 2021
  • 1 reply
  • 391 views

I’ve added the following error handling to the middleware using the ‘afterResponse’ property. This seemed to work for the validation of the action responses but it breaks the authentication which dies with the error below. If I take the ‘afterResponse’ property out authentication works. What am I missing here?const handleErrors = (response, z) => {    // Prevent `throwForStatus` from throwing for a certain status.
if (response.status === 400) {
response.skipThrowForStatus = true;
throw new z.errors.Error(response.json.error.message, response.json.error.code, response.status);
} else if (response.status === 404) {
response.skipThrowForStatus = true;
throw new z.errors.Error(response.json.error.message, response.json.error.code, response.status);
}
};

authentication failed: Middleware should return an object. What happened (You are seeing this because you are an admin): Starting GET request to http://30dd3db01e47.ngrok.io/api/v2/integrations/zapier/me Received 200 code from http://30dd3db01e47.ngrok.io/api/v2/integrations/zapier/me after 982ms Received content "{"success":true,"message":"Successfully authenticated","data":{"account":{"name":"AccountancyManager" Middleware should return an object. Console logs: Stack trace: Error: Middleware should return an object. at Object.collector.then.newOutput (/var/task/node_modules/zapier-platform-core/src/middleware.js:82:19) at bound (domain.js:402:14) at Object.runBound (domain.js:415:12) at Object.tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)

icon

Best answer by Horaland 9 June 2021, 12:54

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Issue resolved.

I was working off the example here https://platform.zapier.com/cli_docs/docs#using-http-middleware but the HandelErrors function requires a 

return response;

As the last line of the function. This is missing from the example but is present in the the sample project in GITHub.