Skip to content

Commit

Permalink
Improve http requests logging
Browse files Browse the repository at this point in the history
- Log request errors, response errors or response not received errors
  • Loading branch information
Uxio0 committed Feb 9, 2024
1 parent 8800009 commit 0f4c3e6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/routes/webhook/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,23 @@ export class WebhookService {
return firstValueFrom(
this.httpService.post(url, parsedMessage, { headers }).pipe(
catchError((error: AxiosError) => {
this.logger.error(`Error sending event to ${url}`, error);
const strMessage = JSON.stringify(parsedMessage);
if (error.response !== undefined) {
// Response received status code but status code not 2xx
this.logger.error(
`Error sending event ${strMessage} to ${url}: ${error.response.status} ${error.response.statusText} - ${error.response.data}`,
);
} else if (error.request !== undefined) {
// Request was made but response was not received
this.logger.error(
`Error sending event ${strMessage} to ${url}: Response not received`,
);
} else {
// Cannot make request
this.logger.error(
`Error sending event ${strMessage} to ${url}: ${error.message}`,
);
}
return of(undefined);
}),
),
Expand Down

0 comments on commit 0f4c3e6

Please sign in to comment.