Skip to content

Commit

Permalink
Patch(service-connector): header interceptor failure log
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Feb 8, 2024
1 parent d38121b commit e82fc2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/service-connector/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const serviceConnector = ({ service, headerIntercepts, loggable, logs = true, ..
if (headerIntercepts) {
let intercepts = headerIntercepts(config);
if (intercepts instanceof Promise)
intercepts = await intercepts.catch((e) => logger.error("Failed to intercept headers", e?.message));
intercepts = await intercepts.catch((e) =>
logger.error(
`Failed to intercept headers - ${coloredString("method")}: ${coloredString(
config.method
)} - ${coloredString("url")}: ${coloredString(`${config.baseURL ?? ""}${config.url}`, "url-value")}`,
e?.message
)
);
config.headers = {
...config.headers,
...intercepts
Expand Down
7 changes: 6 additions & 1 deletion packages/service-connector/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ describe("service-connector", () => {
});
const response = await asyncInterceptedConnector.get("/");
expect(response.status).toEqual(200);
expect(mockLogger.error).toBeCalledWith(`Failed to intercept headers`, undefined);
expect(mockLogger.error).toBeCalledWith(
`Failed to intercept headers - ${coloredString("method")}: ${coloredString("get")} - ${coloredString(
"url"
)}: ${coloredString("https://google.com/", "url-value")}`,
undefined
);
});
});

Expand Down

0 comments on commit e82fc2b

Please sign in to comment.