Skip to content

Commit

Permalink
Undo GraphQL HTTP error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Feb 28, 2019
1 parent cf4dad5 commit bdfbc56
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/index.ts
Expand Up @@ -17,12 +17,23 @@ export function graphqlServie (options: GraphQLOptions | GraphQLOptionsFunction)
const query = method === 'POST' ? await req.body.json() : parseQuery(req.Url.query as string)

const request = { method, url: req.url, headers: req.headers as any }
const gqlResponse = await runHttpQuery([req], { method, options, query, request })

return new Response({
headers: createHeaders(gqlResponse.responseInit.headers),
body: createBody(gqlResponse.graphqlResponse)
})
try {
const gqlResponse = await runHttpQuery([req], { method, options, query, request })

return new Response({
headers: createHeaders(gqlResponse.responseInit.headers),
body: createBody(gqlResponse.graphqlResponse)
})
} catch (err) {
if (err.name !== 'HttpQueryError') throw err

return new Response({
statusCode: err.statusCode,
headers: createHeaders(err.headers as HeadersObject),
body: createBody(err.message as string)
})
}
}
}

Expand Down

0 comments on commit bdfbc56

Please sign in to comment.