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

Improve printing API errors #1071

Merged
merged 2 commits into from
Apr 24, 2019
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ way to update this template, but currently, we follow a pattern:

## Upcoming version 2019-XX-XX

- [add] Improve printing API errors on web inspector (console.table)
[#1070](https://github.com/sharetribe/flex-template-web/pull/1070)
- [fix] ManageAvailabilityCalendar.js didn't use UTC time when fetching data for calendar months.
[#1069](https://github.com/sharetribe/flex-template-web/pull/1069)
- [add] Use sparse fields on InboxPage query to reduce data load.
Expand Down
15 changes: 13 additions & 2 deletions src/util/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export const clearUserId = () => {
});
};

const printAPIErrorsAsConsoleTable = apiErrors => {
if (typeof console.table === 'function') {
console.log('Errors returned by Marketplace API call:');
console.table(apiErrors.map(err => ({ status: err.status, code: err.code, ...err.meta })));
}
};

/**
* Logs an execption. If Sentry is configured
* sends the error information there. Otherwise
Expand All @@ -57,8 +64,9 @@ export const clearUserId = () => {
* @param {Object} data Additional data to be sent to Sentry
*/
export const error = (e, code, data) => {
const apiErrors = responseApiErrorInfo(e);
if (config.sentryDsn) {
const extra = { ...data, apiErrorData: responseApiErrorInfo(e) };
const extra = { ...data, apiErrorData: apiErrors };

Sentry.withScope(scope => {
scope.setTag('code', code);
Expand All @@ -67,8 +75,11 @@ export const error = (e, code, data) => {
});
Sentry.captureException(e);
});

printAPIErrorsAsConsoleTable(apiErrors);
} else {
console.error(e); // eslint-disable-line
console.error(e);
console.error('Error code:', code, 'data:', data);
printAPIErrorsAsConsoleTable(apiErrors);
}
};