Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log error trace in catch blocks #605

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/analytics-core/src/core-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export class AmplitudeCore implements CoreClient {

return result;
} catch (e) {
this.config.loggerProvider.error(e);
kevinpagtakhan marked this conversation as resolved.
Show resolved Hide resolved
const message = String(e);
this.config.loggerProvider.error(message);
const result = buildResult(event, 0, message);

return result;
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-core/src/plugins/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export class Destination implements DestinationPlugin {
}
this.handleResponse(res, list);
} catch (e) {
this.config.loggerProvider.error(e);
const errorMessage = getErrorMessage(e);
this.config.loggerProvider.error(errorMessage);
this.fulfillRequest(list, 0, errorMessage);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-core/test/plugins/destination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ describe('destination', () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(loggerProvider.error).toHaveBeenCalledTimes(1);
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(loggerProvider.error).toHaveBeenCalledWith(message);
expect(loggerProvider.error).toHaveBeenCalledWith(err instanceof Error ? new Error(message) : message);
});

test('should parse response without body', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export const gaEventsForwarderPlugin = ({ measurementIds = [] }: Options = {}):
}
}
return true;
} catch (error) {
} catch (e) {
/* istanbul ignore next */
logger?.error(String(error));
logger?.error(e);
return false;
}
};
Expand Down