Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update devdependencies (major) #198

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/winston": "2.4.4",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@typescript-eslint/eslint-plugin": "6.4.1",
"@typescript-eslint/parser": "6.4.1",
"eslint": "8.47.0",
"husky": "8.0.3",
"lint-staged": "13.3.0",
"lint-staged": "14.0.1",
"prettier": "3.0.2",
"rimraf": "5.0.1",
"ts-node": "10.9.1",
Expand Down
91 changes: 49 additions & 42 deletions src/base/Requestable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosResponse, RawAxiosRequestHeaders, ResponseType } from 'axios';
import axios, { AxiosError, AxiosResponse, RawAxiosRequestHeaders, ResponseType } from 'axios';
import Bottleneck from 'bottleneck';
import { log } from '../logger';
import { EasybillError } from './EasybillError';
Expand Down Expand Up @@ -58,55 +58,62 @@ export class Requestable {
const { method, url, params, data, headers, responseType } = config;

return limiter.schedule(async () => {
try {
const res = await this.axiosInstance.request<T, AxiosResponse<T>>({
const res = await this.axiosInstance
.request<T, AxiosResponse<T>>({
method,
url,
data,
params,
headers,
cancelToken: this.axiosCancelTokenSource.token,
responseType,
});
return res.data;
} catch (error: any) {
// The request was made and the server responded with a status code
if (error.response) {
log({
level: 'error',
message: JSON.stringify(
{
data: error.response.data,
statusCode: error.response.status,
headers: error.response.headers,
},
null,
3,
),
label: 'EasybillAPI',
});
} else if (error.request) {
// The request was made but no response is received. Request is an instance of http.ClientRequest
log({
level: 'error',
message: JSON.stringify(
{
request: error.request,
},
null,
3,
),
label: 'EasybillAPI',
});
}
})
.catch((error: AxiosError) => {
// The request was made and the server responded with a status code
if (error.response) {
log({
level: 'error',
message: JSON.stringify(
{
data: error.response.data,
statusCode: error.response.status,
headers: error.response.headers,
},
null,
3,
),
label: 'EasybillAPI',
});
throw new EasybillError(
error.message,
error.response.status,
error.response.statusText,
error,
);
} else if (error.request) {
// The request was made but no response is received. Request is an instance of http.ClientRequest
log({
level: 'error',
message: JSON.stringify(
{
request: error.request,
},
null,
3,
),
label: 'EasybillAPI',
});
throw new EasybillError(
error.message,
error.request.status,
error.request.statusText,
error,
);
}

throw new EasybillError(
error.message,
error.response?.status,
error.response?.statusText,
error,
);
}
throw new EasybillError(error.message, 500, 'Internal Server Error', error);
});
return res.data;
});
}

Expand Down
Loading