From 48de124a0b8824bbae70e37c880d3e2ab953ad1e Mon Sep 17 00:00:00 2001 From: Dejan Zdravkovic Date: Mon, 21 Mar 2022 14:28:07 +0100 Subject: [PATCH] error response --- README.md | 2 +- src/translate/providers/google-official-api.ts | 2 +- src/translate/translate.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c361c90..3845901 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@

- + diff --git a/src/translate/providers/google-official-api.ts b/src/translate/providers/google-official-api.ts index 3068c7d..61fb0ff 100644 --- a/src/translate/providers/google-official-api.ts +++ b/src/translate/providers/google-official-api.ts @@ -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}`); diff --git a/src/translate/translate.ts b/src/translate/translate.ts index 7136706..b10a5c0 100644 --- a/src/translate/translate.ts +++ b/src/translate/translate.ts @@ -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); } };