Skip to content

Commit

Permalink
Update httpResponse error message (#228)
Browse files Browse the repository at this point in the history
* Fix message when and error dont have a Response Data

* Modify httpResponse logs in some cases

* Add httpRequestError object to catch all errors when the response is not
received

* Apply linter changes
  • Loading branch information
diegopazosrego authored May 8, 2024
1 parent bf1be8b commit d70ee79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/routes/webhook/webhook.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,17 @@ describe('Webhook service', () => {
headers: {},
});
expect(loggerErrorSpy).toHaveBeenCalledWith({
message: `Error sending event: Response not received. Error: ${errorMessageMocked}`,
message: 'Error sending event',
messageContext: {
event: event,
httpRequest: {
url: url,
startTime: expect.any(Number),
},
httpResponse: null,
httpRequestError: {
message: expect.stringContaining('Response not received. Error:'),
},
},
});
});
Expand Down Expand Up @@ -312,14 +315,17 @@ describe('Webhook service', () => {
headers: {},
});
expect(loggerErrorSpy).toHaveBeenCalledWith({
message: `Error sending event: ${errorMessage}`,
message: 'Error sending event',
messageContext: {
event: event,
httpRequest: {
url: url,
startTime: expect.any(Number),
},
httpResponse: null,
httpRequestError: {
message: expect.any(String),
},
},
});
});
Expand Down
10 changes: 8 additions & 2 deletions src/routes/webhook/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,33 @@ export class WebhookService {
} else if (error.request !== undefined) {
// Request was made but response was not received
this.logger.error({
message: `Error sending event: Response not received. Error: ${error.message}`,
message: 'Error sending event',
messageContext: {
event: parsedMessage,
httpRequest: {
url: url,
startTime: startTime,
},
httpResponse: null,
httpRequestError: {
message: `Response not received. Error: ${error.message}`,
},
},
});
} else {
// Cannot make request
this.logger.error({
message: `Error sending event: ${error.message}`,
message: 'Error sending event',
messageContext: {
event: parsedMessage,
httpRequest: {
url: url,
startTime: startTime,
},
httpResponse: null,
httpRequestError: {
message: error.message,
},
},
});
}
Expand Down

0 comments on commit d70ee79

Please sign in to comment.