Skip to content

Commit

Permalink
error response
Browse files Browse the repository at this point in the history
  • Loading branch information
while1618 committed Mar 21, 2022
1 parent b2d8454 commit 48de124
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<p align="center">
<a href="https://www.npmjs.com/package/i18n-auto-translation" alt="NPM Version">
<img src="https://img.shields.io/badge/npm-v1.1.5-blue" />
<img src="https://img.shields.io/badge/npm-v1.1.6-blue" />
</a>
<a href="LICENSE" alt="License">
<img src="https://img.shields.io/github/license/while1618/i18n-auto-translation" />
Expand Down
2 changes: 1 addition & 1 deletion src/translate/providers/google-official-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class GoogleOfficialAPI extends Translate {
})
.catch((error) => {
const err = error as ErrorResponse;
if (err.response.statusCode && err.response.statusMessage && err.errors[0].message) {
if (err.response?.statusCode && err.response.statusMessage && err.errors[0].message) {
console.error('Google Translate API Request Error!');
console.log(`Status Code: ${err.response.statusCode}`);
console.log(`Status Text: ${err.response.statusMessage}`);
Expand Down
4 changes: 2 additions & 2 deletions src/translate/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ export abstract class Translate {
) => void;

protected printAxiosError = (error: AxiosError, api: string): void => {
console.error(`${api} Request Error!`);
if (error.response?.status && error.response.statusText && error.response.data) {
console.error(`${api} Request Error!`);
console.log(`Status Code: ${error.response?.status}`);
console.log(`Status Text: ${error.response?.statusText}`);
console.log(`Data: ${JSON.stringify(error.response?.data)}`);
} else {
console.log(error);
console.log(error.message);
}
};

Expand Down

0 comments on commit 48de124

Please sign in to comment.