check response for errors

This commit is contained in:
Matthias Stallmann 2024-09-12 16:59:44 +02:00
parent a0af1d9a06
commit 7039173b06

View file

@ -37,7 +37,22 @@ export async function mondayComApiRequest(
if (authenticationMethod === 'oAuth2') {
credentialType = 'mondayComOAuth2Api';
}
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
const responseData = await this.helpers.requestWithAuthentication.call(
this,
credentialType,
options,
);
if (
responseData.hasOwnProperty('error_message') ||
responseData.hasOwnProperty('error_code') ||
responseData.hasOwnProperty('errors')
) {
throw new NodeApiError(this.getNode(), responseData as JsonObject);
}
return responseData;
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
@ -88,6 +103,14 @@ export async function mondayComApiPaginatedRequest(
})) as IDataObject
).data as { next_items_page: { cursor: string; items: IDataObject[] } };
if (
responseData.hasOwnProperty('error_message') ||
responseData.hasOwnProperty('error_code') ||
responseData.hasOwnProperty('errors')
) {
throw new NodeApiError(this.getNode(), responseData as JsonObject);
}
if (responseData && responseData.next_items_page) {
returnData.push.apply(returnData, responseData.next_items_page.items);
cursor = responseData.next_items_page.cursor;