getStatusCode(); $responsePhrase = $status < 400 ? 'Internal Server Error' : $response->getReasonPhrase(); $status = $status < 400 ? 500 : $status; return new JsonResponse([ 'error' => $this->responsePhraseToCode($responsePhrase), 'message' => $responsePhrase, ], $status); } /** * @param string $responsePhrase * @return string */ protected function responsePhraseToCode($responsePhrase) { return strtoupper(str_replace(' ', '_', $responsePhrase)); } }