Skip to content

Commit

Permalink
579-added the global error class and axios request and response types
Browse files Browse the repository at this point in the history
  • Loading branch information
sangeet-joy-tw committed Jan 30, 2024
1 parent d3dbd85 commit f268380
Show file tree
Hide file tree
Showing 21 changed files with 2,496 additions and 11,363 deletions.
6,873 changes: 1,182 additions & 5,691 deletions src/gen/api/accountingApi.ts

Large diffs are not rendered by default.

119 changes: 22 additions & 97 deletions src/gen/api/appStoreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* Do not edit the class manually.
*/

const axios = require('axios');
import http = require('http');
import fs = require('fs');

Expand All @@ -23,6 +22,8 @@ import { UsageRecord } from '../model/appstore/usageRecord';
import { UsageRecordsList } from '../model/appstore/usageRecordsList';

import { ObjectSerializer, Authentication, VoidAuth } from '../model/appstore/models';
import { ApiError } from '../../model/ApiError';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { OAuth } from '../model/appstore/models';

let defaultBasePath = 'https://api.xero.com/appstore/2.0';
Expand Down Expand Up @@ -87,7 +88,7 @@ export class AppStoreApi {
* @summary Retrieves a subscription for a given subscriptionId
* @param subscriptionId Unique identifier for Subscription object
*/
public async getSubscription (subscriptionId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: Subscription; }> {
public async getSubscription (subscriptionId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: Subscription; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)));
let localVarQueryParameters: any = {};
Expand All @@ -107,7 +108,7 @@ export class AppStoreApi {
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

let localVarRequestOptions = {
let localVarRequestOptions: AxiosRequestConfig = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
Expand All @@ -116,26 +117,6 @@ export class AppStoreApi {
data: {},
};

const generateCustomError = (error) => {
return JSON.stringify({
response: {
statusCode: error.response.status,
body: error.response.data,
headers: error.response.headers,
request: {
url: {
protocol: error.request.protocol,
port: error.request.agent.defaultPort,
host: error.request.host,
path: error.request.path,
},
headers: error.request.getHeaders(),
method: error.request.method
},
},
body: error.response.data
});
}
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));

Expand All @@ -150,7 +131,7 @@ export class AppStoreApi {
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: http.IncomingMessage; body: Subscription; }>(async (resolve, reject) => {
return new Promise<{ response: AxiosResponse; body: Subscription; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
Expand All @@ -162,7 +143,8 @@ export class AppStoreApi {
}
}
catch(error) {
reject(generateCustomError(error))
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
Expand All @@ -172,7 +154,7 @@ export class AppStoreApi {
* @summary Gets all usage records related to the subscription
* @param subscriptionId Unique identifier for Subscription object
*/
public async getUsageRecords (subscriptionId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: UsageRecordsList; }> {
public async getUsageRecords (subscriptionId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: UsageRecordsList; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}/usage-records'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)));
let localVarQueryParameters: any = {};
Expand All @@ -192,7 +174,7 @@ export class AppStoreApi {
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

let localVarRequestOptions = {
let localVarRequestOptions: AxiosRequestConfig = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
Expand All @@ -201,26 +183,6 @@ export class AppStoreApi {
data: {},
};

const generateCustomError = (error) => {
return JSON.stringify({
response: {
statusCode: error.response.status,
body: error.response.data,
headers: error.response.headers,
request: {
url: {
protocol: error.request.protocol,
port: error.request.agent.defaultPort,
host: error.request.host,
path: error.request.path,
},
headers: error.request.getHeaders(),
method: error.request.method
},
},
body: error.response.data
});
}
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));

Expand All @@ -235,7 +197,7 @@ export class AppStoreApi {
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: http.IncomingMessage; body: UsageRecordsList; }>(async (resolve, reject) => {
return new Promise<{ response: AxiosResponse; body: UsageRecordsList; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
Expand All @@ -247,7 +209,8 @@ export class AppStoreApi {
}
}
catch(error) {
reject(generateCustomError(error))
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
Expand All @@ -260,7 +223,7 @@ export class AppStoreApi {
* @param createUsageRecord Contains the quantity for the usage record to create
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
*/
public async postUsageRecords (subscriptionId: string, subscriptionItemId: string, createUsageRecord: CreateUsageRecord, idempotencyKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: UsageRecord; }> {
public async postUsageRecords (subscriptionId: string, subscriptionItemId: string, createUsageRecord: CreateUsageRecord, idempotencyKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: UsageRecord; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}/items/{subscriptionItemId}/usage-records'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)))
.replace('{' + 'subscriptionItemId' + '}', encodeURIComponent(String(subscriptionItemId)));
Expand Down Expand Up @@ -292,7 +255,7 @@ export class AppStoreApi {
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

let localVarRequestOptions = {
let localVarRequestOptions: AxiosRequestConfig = {
method: 'POST',
params: localVarQueryParameters,
headers: localVarHeaderParams,
Expand All @@ -301,26 +264,6 @@ export class AppStoreApi {
data: ObjectSerializer.serialize(createUsageRecord, "CreateUsageRecord"),
};

const generateCustomError = (error) => {
return JSON.stringify({
response: {
statusCode: error.response.status,
body: error.response.data,
headers: error.response.headers,
request: {
url: {
protocol: error.request.protocol,
port: error.request.agent.defaultPort,
host: error.request.host,
path: error.request.path,
},
headers: error.request.getHeaders(),
method: error.request.method
},
},
body: error.response.data
});
}
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));

Expand All @@ -335,7 +278,7 @@ export class AppStoreApi {
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: http.IncomingMessage; body: UsageRecord; }>(async (resolve, reject) => {
return new Promise<{ response: AxiosResponse; body: UsageRecord; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
Expand All @@ -347,7 +290,8 @@ export class AppStoreApi {
}
}
catch(error) {
reject(generateCustomError(error))
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
Expand All @@ -361,7 +305,7 @@ export class AppStoreApi {
* @param updateUsageRecord Contains the quantity for the usage record to update
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
*/
public async putUsageRecords (subscriptionId: string, subscriptionItemId: string, usageRecordId: string, updateUsageRecord: UpdateUsageRecord, idempotencyKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: UsageRecord; }> {
public async putUsageRecords (subscriptionId: string, subscriptionItemId: string, usageRecordId: string, updateUsageRecord: UpdateUsageRecord, idempotencyKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: UsageRecord; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}/items/{subscriptionItemId}/usage-records/{usageRecordId}'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)))
.replace('{' + 'subscriptionItemId' + '}', encodeURIComponent(String(subscriptionItemId)))
Expand Down Expand Up @@ -399,7 +343,7 @@ export class AppStoreApi {
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;

let localVarRequestOptions = {
let localVarRequestOptions: AxiosRequestConfig = {
method: 'PUT',
params: localVarQueryParameters,
headers: localVarHeaderParams,
Expand All @@ -408,26 +352,6 @@ export class AppStoreApi {
data: ObjectSerializer.serialize(updateUsageRecord, "UpdateUsageRecord"),
};

const generateCustomError = (error) => {
return JSON.stringify({
response: {
statusCode: error.response.status,
body: error.response.data,
headers: error.response.headers,
request: {
url: {
protocol: error.request.protocol,
port: error.request.agent.defaultPort,
host: error.request.host,
path: error.request.path,
},
headers: error.request.getHeaders(),
method: error.request.method
},
},
body: error.response.data
});
}
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));

Expand All @@ -442,7 +366,7 @@ export class AppStoreApi {
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: http.IncomingMessage; body: UsageRecord; }>(async (resolve, reject) => {
return new Promise<{ response: AxiosResponse; body: UsageRecord; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
Expand All @@ -454,7 +378,8 @@ export class AppStoreApi {
}
}
catch(error) {
reject(generateCustomError(error))
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
Expand Down
Loading

0 comments on commit f268380

Please sign in to comment.