Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Handle empty body #174

Open
ojongerius opened this issue May 18, 2018 · 1 comment
Open

Handle empty body #174

ojongerius opened this issue May 18, 2018 · 1 comment

Comments

@ojongerius
Copy link
Contributor

Hitting Graphql with an empty body is not supported, but we currently expose an error from apollo-server, which we should dress up a little nicer.

▶ curl -X POST https://hxtsoafqna.execute-api.us-east-1.amazonaws.com/stage/graphql
POST body missing. Did you forget use body-parser middleware?%

Find code that generates the error at https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/runHttpQuery.ts#L67

 switch (request.method) {
    case 'POST':
      if (!request.query || Object.keys(request.query).length === 0) {
        throw new HttpQueryError(
          500,
          'POST body missing. Did you forget use body-parser middleware?',
        );
      }
@sivakar12
Copy link
Contributor

'apollo-server-core' is throwing the error but out 'apollo-server-lambda' hander is catching the error and adding the error message
https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-lambda/src/lambdaApollo.ts

try {
      gqlResponse = await runHttpQuery([event, lambdaContext], {
        method: event.httpMethod,
        options: options,
        query: query,
      });
      headers['Content-Type'] = 'application/json';
      statusCode = 200;
    } catch (error) {
      if ('HttpQueryError' !== error.name) {
        throw error;
      }

      headers = error.headers;
      statusCode = error.statusCode;
      gqlResponse = error.message;
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants