Skip to content

Commit

Permalink
fix: defensively parse fetch request body
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobadini committed Jan 9, 2024
1 parent 2d21c67 commit d30718d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/lib/shopify-storefront-sdk/generated/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ export enum CountryCode {
Tn = 'TN',
/** Tonga. */
To = 'TO',
/** Turkey. */
/** Türkiye. */
Tr = 'TR',
/** Trinidad & Tobago. */
Tt = 'TT',
Expand Down
9 changes: 8 additions & 1 deletion packages/sentry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ const withSentry: FetchMiddleware = (fetcher) => async (input, init) => {
});
}

let body;
try {
body = init?.body ? JSON.parse(String(init?.body)) : undefined;
} catch (e) {
body = init?.body ?? undefined;
}

const context = {
// Underscore sorts the resource first in Sentry's UI
_resource: input,
headers: init?.headers,
method: init?.method,
// Parse to pretty print GraphQL queries
body: init?.body ? JSON.parse(String(init?.body)) : undefined,
body,
};
try {
const response = await fetcher(input, init);
Expand Down

0 comments on commit d30718d

Please sign in to comment.