Skip to content

Commit

Permalink
Merge pull request #7002 from vuestorefront/fix/main-resolving-apollo…
Browse files Browse the repository at this point in the history
…-status-code

fix: resolving apollo client status code
  • Loading branch information
bartoszherba authored Dec 21, 2023
2 parents 3e5e55c + 6c769c7 commit 1f3b710
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eleven-games-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-storefront/middleware": patch
---

Fix status code resolving for the apollo client
2 changes: 1 addition & 1 deletion packages/middleware/src/errors/defaultErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const defaultErrorHandler = (
consola.error(error);
const status = getAgnosticStatusCode(error);
res.status(status);
if (status >= 400 && status < 500) {
if (status < 500) {
/**
* For all 4xx error codes or client error codes we wanted to send the error message
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/middleware/src/helpers/getAgnosticStatusCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function getApolloStatusCode(error: ApolloError) {
if (error.code) {
return typeof error.code === "string" ? 400 : error.code;
}

if (error?.graphQLErrors?.length > 0) {
return 200;
}

return undefined;
}

Expand Down
1 change: 1 addition & 0 deletions packages/middleware/src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type AxiosError = {
export type ApolloError = {
networkError?: number;
code?: string | number;
graphQLErrors: Array<any>;
};

export type StatusCode = number | null;
Expand Down

0 comments on commit 1f3b710

Please sign in to comment.