Small improvements to Zendesk-Node

This commit is contained in:
Jan Oberhauser
2020-04-09 00:31:39 +02:00
parent f5d52a50cb
commit d0c8e3f4e7
2 changed files with 9 additions and 2 deletions

View File

@@ -34,7 +34,14 @@ export async function zendeskApiRequest(this: IHookFunctions | IExecuteFunctions
try {
return await this.helpers.request!(options);
} catch (err) {
const errorMessage = err.response.body.description || err.response.body;
let errorMessage = err.message;
if (err.response && err.response.body && err.response.body.error) {
errorMessage = err.response.body.error;
if (typeof err.response.body.error !== 'string') {
errorMessage = JSON.stringify(errorMessage);
}
}
throw new Error(`Zendesk error response [${err.statusCode}]: ${errorMessage}`);
}
}