Skip to content

Commit

Permalink
fix: Added response context to message
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Oct 5, 2023
1 parent c0a876b commit ddf024c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/terrasoApi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import logger from 'terraso-client-shared/monitoring/logger';
type Error = { message: any };
type Errors = { errors?: Error[] | null };

const parseMessage = (message: any, body: any) => {
const parseMessage = (message: any, body: any, response: any) => {
try {
const messages = (function () {
// If message can be parsed as JSON, return parsed messages
Expand Down Expand Up @@ -54,6 +54,7 @@ const parseMessage = (message: any, body: any) => {
..._.omit('extra', message.context),
context: _.get('context.extra', message),
body: _.omit('query', body),
response: _.omit('errors', response),
},
};
});
Expand Down Expand Up @@ -85,7 +86,7 @@ const handleApiErrors = async <T extends Errors>(
body instanceof FormData ? JSON.parse(JSON.stringify(body)) : body;

const messages = _.flatMap(
error => parseMessage(error.message, parsedBody),
error => parseMessage(error.message, parsedBody, response),
response.errors,
);
return Promise.reject(messages);
Expand Down

0 comments on commit ddf024c

Please sign in to comment.