Skip to content

Commit

Permalink
Merge pull request #13904 from mozilla/FXA-5679-l-10-n-export-is-brok…
Browse files Browse the repository at this point in the history
  • Loading branch information
dschom authored Aug 9, 2022
2 parents d84af5e + 8b741d2 commit b3947c8
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/fxa-content-server/server/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,29 @@ if (config.get('sentry.dsn')) {
*/
function tryCaptureValidationError(err) {
try {
const errorDetails =
err?.details instanceof Map && err?.details?.get('body');
// Try to get error details. This might not be present.
let errorDetails = null;
if (err != null && err.details instanceof Map) {
errorDetails = err.details.get('body');
}

if (errorDetails) {
const message = `${errorDetails}`;
const validationError = errorDetails.details.reduce((a, v) => {
return {
...a,
[v?.path?.join('.')]: `reason: ${v.type} - ${v.message}`,
};
// Try to get the key for the field that failed validation and update
// the error state
if (v && Array.isArray(v.path)) {
const key = v.path.join('.');

if (key) {
return {
...a,
[key]: `reason: ${v.type} - ${v.message}`,
};
}
}

return a;
}, {});

Sentry.withScope((scope) => {
Expand Down

0 comments on commit b3947c8

Please sign in to comment.