File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -128,14 +128,15 @@ private function decideHttpStatusCode(ExecutionResult $result): int
128
128
$ status = 0 ;
129
129
// There might be many errors. Let's return the highest code we encounter.
130
130
foreach ($ result ->errors as $ error ) {
131
- if ($ error ->getCategory () === Error::CATEGORY_GRAPHQL ) {
132
- $ code = 400 ;
133
- } else {
134
- $ code = $ error ->getCode ();
131
+ $ wrappedException = $ error ->getPrevious ();
132
+ if ($ wrappedException !== null ) {
133
+ $ code = $ wrappedException ->getCode ();
135
134
if (!isset (Response::$ statusTexts [$ code ])) {
136
135
// The exception code is not a valid HTTP code. Let's ignore it
137
136
continue ;
138
137
}
138
+ } else {
139
+ $ code = 400 ;
139
140
}
140
141
$ status = max ($ status , $ code );
141
142
}
Original file line number Diff line number Diff line change 4
4
namespace TheCodingMachine \Graphqlite \Bundle \Tests \Fixtures \Controller ;
5
5
6
6
7
+ use GraphQL \Error \Error ;
7
8
use Porpaginas \Arrays \ArrayResult ;
8
9
use TheCodingMachine \Graphqlite \Bundle \Tests \Fixtures \Entities \Contact ;
9
10
use TheCodingMachine \Graphqlite \Bundle \Tests \Fixtures \Entities \Product ;
@@ -61,7 +62,7 @@ public function contacts(): ArrayResult
61
62
* @Query()
62
63
* @return string
63
64
*/
64
- public function triggerError (int $ code = 500 ): string
65
+ public function triggerException (int $ code = 500 ): string
65
66
{
66
67
throw new MyException ('Boom ' , $ code );
67
68
}
Original file line number Diff line number Diff line change @@ -106,16 +106,19 @@ public function testErrors()
106
106
107
107
$ request = Request::create ('/graphql ' , 'GET ' , ['query ' => '
108
108
{
109
- triggerError
109
+ triggerException
110
110
} ' ]);
111
111
112
112
$ response = $ kernel ->handle ($ request );
113
113
114
114
$ this ->assertSame (500 , $ response ->getStatusCode ());
115
115
116
+ // Let's test that the highest exception code compatible with an HTTP is kept.
116
117
$ request = Request::create ('/graphql ' , 'GET ' , ['query ' => '
117
118
{
118
- triggerError(code: 404)
119
+ triggerError1: triggerException(code: 404)
120
+ triggerError2: triggerException(code: 401)
121
+ triggerError3: triggerException(code: 10245)
119
122
} ' ]);
120
123
121
124
$ response = $ kernel ->handle ($ request );
You can’t perform that action at this time.
0 commit comments