data !== null && empty($result->errors)) { return 200; } $status = 0; // There might be many errors. Let's return the highest code we encounter. foreach ($result->errors as $error) { $wrappedException = $error->getPrevious(); if ($wrappedException !== null) { $code = $wrappedException->getCode(); if ($code < 400 || $code >= 600) { if (! ($wrappedException instanceof ClientAware) || $wrappedException->isClientSafe() !== true) { // The exception code is not a valid HTTP code. Let's ignore it continue; } // A "client aware" exception is almost certainly targeting the client (there is // no need to pass a server exception error message to the client). // So a ClientAware exception is almost certainly a HTTP 400 code $code = 400; } } else { $code = 400; } $status = (int) max($status, $code); } // If exceptions have been thrown, and they have not an "HTTP like code", let's throw a 500. if ($status < 200) { $status = 500; } return $status; } }