Skip to content

Commit

Permalink
allow client side code to throw HttpError
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Aug 17, 2021
1 parent ee11111 commit dea3700
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-pillows-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"graphql-helix": minor
---

allow client side code to throw HttpError, Thanks @mosch
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./get-graphql-parameters";
export * from "./process-request";
export * from "./should-render-graphiql";
export * from "./types";
export * from "./errors";
18 changes: 11 additions & 7 deletions packages/core/src/process-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,17 @@ export const processRequest = async <TContext = {}, TRootValue = {}>(
}
}
} catch (executionError: any) {
throw new HttpError(
500,
"Unexpected error encountered while executing GraphQL request.",
{
graphqlErrors: [new GraphQLError(executionError.message)],
}
);
if (executionError instanceof HttpError) {
throw executionError;
} else {
throw new HttpError(
500,
"Unexpected error encountered while executing GraphQL request.",
{
graphqlErrors: [new GraphQLError(executionError.message)],
}
);
}
}
} catch (error: any) {
const payload = {
Expand Down

0 comments on commit dea3700

Please sign in to comment.