Skip to content

Commit

Permalink
moved missing multipart accept header error into errors.js
Browse files Browse the repository at this point in the history
  • Loading branch information
igrlk committed Oct 26, 2022
1 parent 35fdb02 commit d41fff6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const {
MER_ERR_GQL_VALIDATION,
MER_ERR_INVALID_OPTS,
MER_ERR_METHOD_NOT_ALLOWED,
MER_ERR_INVALID_METHOD
MER_ERR_INVALID_METHOD,
MER_ERR_INVALID_MULTIPART_ACCEPT_HEADER
} = require('./lib/errors')
const { Hooks, assignLifeCycleHooksToContext } = require('./lib/hooks')
const { kLoaders, kFactory, kSubscriptionFactory, kHooks } = require('./lib/symbols')
Expand Down Expand Up @@ -577,12 +578,7 @@ const plugin = fp(async function (app, opts) {
) {
// The client ran an operation that would yield multiple parts, but didn't
// specify `accept: multipart/mixed`. We return an error.
throw new Error(
'Server received an operation that uses incremental delivery ' +
'(@defer or @stream), but the client does not accept multipart/mixed ' +
'HTTP responses. To enable incremental delivery support, add the HTTP ' +
"header 'Accept: multipart/mixed; deferSpec=20220824'."
)
throw new MER_ERR_INVALID_MULTIPART_ACCEPT_HEADER()
}

reply.header('content-type', 'multipart/mixed; boundary="-"; deferSpec=20220824')
Expand Down
4 changes: 4 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ const errors = {
'Method not allowed',
405
),
MER_ERR_INVALID_MULTIPART_ACCEPT_HEADER: createError(
'MER_ERR_INVALID_MULTIPART_ACCEPT_HEADER',
'Server received an operation that uses incremental delivery (@defer or @stream), but the client does not accept multipart/mixed HTTP responses. To enable incremental delivery support, add the HTTP header "Accept: multipart/mixed; deferSpec=20220824".'
),
/**
* General graphql errors
*/
Expand Down
4 changes: 2 additions & 2 deletions test/defer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ if (canUseIncrementalExecution) {
})

t.match(res, {
statusCode: 200,
statusCode: 500,
body: JSON.stringify({
data: null,
errors: [{
message: "Server received an operation that uses incremental delivery (@defer or @stream), but the client does not accept multipart/mixed HTTP responses. To enable incremental delivery support, add the HTTP header 'Accept: multipart/mixed; deferSpec=20220824'."
message: 'Server received an operation that uses incremental delivery (@defer or @stream), but the client does not accept multipart/mixed HTTP responses. To enable incremental delivery support, add the HTTP header "Accept: multipart/mixed; deferSpec=20220824".'
}]
})
})
Expand Down

0 comments on commit d41fff6

Please sign in to comment.