Small improvements to Jira-Node

This commit is contained in:
Jan Oberhauser
2020-04-24 09:50:56 +02:00
parent 57d296d30a
commit f8869f85e8
3 changed files with 42 additions and 18 deletions

View File

@@ -43,11 +43,21 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
try {
return await this.helpers.request!(options);
} catch (error) {
const errorMessage = error.response.body.message || error.response.body.error || error.response.body.errors;
if (errorMessage !== undefined) {
throw new Error(errorMessage);
let errorMessage = error.message;
if (error.response.body) {
if (error.response.body.errorMessages && error.response.body.errorMessages.length) {
errorMessage = JSON.stringify(error.response.body.errorMessages);
} else {
errorMessage = error.response.body.message || error.response.body.error || error.response.body.errors || error.message;
}
}
throw error;
if (typeof errorMessage !== 'string') {
errorMessage = JSON.stringify(errorMessage);
}
throw new Error(`Jira error response [${error.statusCode}]: ${errorMessage}`);
}
}