@sp-api-sdk/common
Version:
Selling Parner API common library
22 lines (21 loc) • 832 B
JavaScript
import { URL } from 'node:url';
import { AxiosError } from 'axios';
export class SellingPartnerApiError extends AxiosError {
innerMessage;
apiName;
apiVersion;
constructor(error) {
super('Unknown error', error.code, error.config, error.request, error.response);
this.innerMessage = error.message;
if (error.config.url) {
const [apiName, apiVersion] = new URL(error.config.url).pathname.split('/').slice(1);
const apiPrefix = `${apiName} (${apiVersion})`;
this.apiName = apiName;
this.apiVersion = apiVersion;
this.message = error.response
? `${apiPrefix} error: Response code ${error.response.status}`
: `${apiPrefix} error: No response`;
}
this.name = this.constructor.name;
}
}