Skip to content

Commit f07454d

Browse files
committed
fix(handler): Match status text with status code
1 parent 63d1fac commit f07454d

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/handler.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,15 @@ export function createHandler<RawRequest = unknown>(
363363
return [
364364
err.message,
365365
{
366-
status: acceptedMediaType === 'application/json' ? 200 : 400,
366+
...(acceptedMediaType === 'application/json'
367+
? {
368+
status: 200,
369+
statusText: 'OK',
370+
}
371+
: {
372+
status: 400,
373+
statusText: 'Bad Request',
374+
}),
367375
statusText: 'Bad Request',
368376
},
369377
];
@@ -385,7 +393,15 @@ export function createHandler<RawRequest = unknown>(
385393
return [
386394
'GraphQL query syntax error',
387395
{
388-
status: acceptedMediaType === 'application/json' ? 200 : 400,
396+
...(acceptedMediaType === 'application/json'
397+
? {
398+
status: 200,
399+
statusText: 'OK',
400+
}
401+
: {
402+
status: 400,
403+
statusText: 'Bad Request',
404+
}),
389405
statusText: 'Bad Request',
390406
},
391407
];
@@ -421,7 +437,15 @@ export function createHandler<RawRequest = unknown>(
421437
return [
422438
'Unable to detect operation AST',
423439
{
424-
status: acceptedMediaType === 'application/json' ? 200 : 400,
440+
...(acceptedMediaType === 'application/json'
441+
? {
442+
status: 200,
443+
statusText: 'OK',
444+
}
445+
: {
446+
status: 400,
447+
statusText: 'Bad Request',
448+
}),
425449
statusText: 'Bad Request',
426450
},
427451
];
@@ -464,8 +488,15 @@ export function createHandler<RawRequest = unknown>(
464488
return [
465489
JSON.stringify({ errors: validationErrs }),
466490
{
467-
status: acceptedMediaType === 'application/json' ? 200 : 400,
468-
statusText: 'Bad Request',
491+
...(acceptedMediaType === 'application/json'
492+
? {
493+
status: 200,
494+
statusText: 'OK',
495+
}
496+
: {
497+
status: 400,
498+
statusText: 'Bad Request',
499+
}),
469500
headers: {
470501
'content-type':
471502
acceptedMediaType === 'application/json'

0 commit comments

Comments
 (0)