Skip to content

Commit

Permalink
Log upstream errors
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Apr 22, 2022
1 parent fb39684 commit c9b423e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { ClientRequest } from 'http';
import { HttpService } from '@nestjs/axios';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import {
Expand Down Expand Up @@ -239,8 +240,13 @@ export class TokensService {
private async wrapError<T>(response: Promise<AxiosResponse<T>>) {
return response.catch(err => {
if (axios.isAxiosError(err)) {
const errorMessage = err.response?.data?.error;
throw new InternalServerErrorException(errorMessage ?? err.message);
const request: ClientRequest | undefined = err.request;
const response: AxiosResponse | undefined = err.response;
const errorMessage = response?.data?.error ?? err.message;
this.logger.warn(
`${request?.path} <-- HTTP ${response?.status} ${response?.statusText}: ${errorMessage}`,
);
throw new InternalServerErrorException(errorMessage);
}
throw err;
});
Expand Down

0 comments on commit c9b423e

Please sign in to comment.