Skip to content

Commit

Permalink
fix(error handling): always returns 200
Browse files Browse the repository at this point in the history
Same reasoning as
graphql/express-graphql#116 (comment)

Hope it doesn't break #25
  • Loading branch information
Christophe Badoit committed Nov 29, 2018
1 parent 3635244 commit 798217e
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/GraphQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class GraphQLController extends Controller {
* @return \Illuminate\Http\JsonResponse
*/
public function query(Request $request, $schema = null) {

$inputs = $request->all();
$data = [];

Expand All @@ -48,11 +49,8 @@ public function query(Request $request, $schema = null) {
$data = $this->executeQuery($schema, $inputs);
}

$responseCode = 200;
} catch (\Exception $exception) {
$data = GraphQL::formatGraphQLException($exception);
$responseCode = 500;

Log::debug($exception);
}

Expand All @@ -61,7 +59,6 @@ public function query(Request $request, $schema = null) {
if ($hasError) {
// Rollback transaction is any error occurred
DB::rollBack();
$responseCode = 422;
} else {
// If everything is okay, just commit the transaction
DB::commit();
Expand All @@ -70,7 +67,7 @@ public function query(Request $request, $schema = null) {
$headers = config('graphql.response.headers', []);
$options = config('graphql.response.json_encoding_options', 0);

return Response::json($data, $responseCode, $headers, $options);
return Response::json($data, 200, $headers, $options);
}

/**
Expand Down

0 comments on commit 798217e

Please sign in to comment.