🚧 Node logic / Genericfunctions setup

This commit is contained in:
Rupenieks
2020-06-30 17:38:55 +02:00
parent b46a29b1a7
commit 4a968ee8ea
5 changed files with 254 additions and 52 deletions

View File

@@ -16,26 +16,24 @@ import {
export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('paddleApi');
const options = {
if (credentials === undefined) {
throw new Error('Could not retrieve credentials!');
}
const options : OptionsWithUri = {
method,
qs: query || {},
uri: uri || `${env}/v1${endpoint}`,
uri: `https://vendors.paddle.com/api${endpoint}` ,
body,
json: true
};
body.vendor_id = credentials.vendorId;
body.vendor_auth_code = credentials.vendorAuthCode;
try {
return await this.helpers.request!(options);
} catch (error) {
if (error.response.body) {
let errorMessage = error.response.body.message;
if (error.response.body.details) {
errorMessage += ` - Details: ${JSON.stringify(error.response.body.details)}`;
}
throw new Error(errorMessage);
}
throw error;
console.log(error);
throw new Error(error);
}
}