protected function HttpExceptionNormalizer::buildErrorObjects in JSON:API 8
Same name and namespace in other branches
- 8.2 src/Normalizer/HttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer::buildErrorObjects()
Builds the normalized JSON API error objects for the response.
Parameters
\Symfony\Component\HttpKernel\Exception\HttpException $exception: The Exception.
Return value
array The error objects to include in the response.
3 calls to HttpExceptionNormalizer::buildErrorObjects()
- EntityAccessDeniedHttpExceptionNormalizer::buildErrorObjects in src/
Normalizer/ EntityAccessDeniedHttpExceptionNormalizer.php - Builds the normalized JSON API error objects for the response.
- HttpExceptionNormalizer::normalize in src/
Normalizer/ HttpExceptionNormalizer.php - Normalizes an object into a set of arrays/scalars.
- UnprocessableHttpEntityExceptionNormalizer::buildErrorObjects in src/
Normalizer/ UnprocessableHttpEntityExceptionNormalizer.php - Builds the normalized JSON API error objects for the response.
2 methods override HttpExceptionNormalizer::buildErrorObjects()
- EntityAccessDeniedHttpExceptionNormalizer::buildErrorObjects in src/
Normalizer/ EntityAccessDeniedHttpExceptionNormalizer.php - Builds the normalized JSON API error objects for the response.
- UnprocessableHttpEntityExceptionNormalizer::buildErrorObjects in src/
Normalizer/ UnprocessableHttpEntityExceptionNormalizer.php - Builds the normalized JSON API error objects for the response.
File
- src/
Normalizer/ HttpExceptionNormalizer.php, line 76
Class
- HttpExceptionNormalizer
- Normalizes an HttpException in compliance with the JSON API specification.
Namespace
Drupal\jsonapi\NormalizerCode
protected function buildErrorObjects(HttpException $exception) {
$error = [];
$status_code = $exception
->getStatusCode();
if (!empty(Response::$statusTexts[$status_code])) {
$error['title'] = Response::$statusTexts[$status_code];
}
$error += [
'status' => $status_code,
'detail' => $exception
->getMessage(),
];
if ($info_url = $this
->getInfoUrl($status_code)) {
$error['links']['info'] = $info_url;
}
$error['code'] = $exception
->getCode();
// Exceptions thrown without an explicitly defined code get assigned zero by
// default. Since this is no helpful information, omit it.
if ($exception
->getCode() !== 0) {
$error['code'] = $exception
->getCode();
}
if ($this->currentUser
->hasPermission('access site reports')) {
// The following information may contain sensitive information. Only show
// it to authorized users.
$error['source'] = [
'file' => $exception
->getFile(),
'line' => $exception
->getLine(),
];
$error['meta'] = [
'exception' => (string) $exception,
'trace' => $exception
->getTrace(),
];
}
return [
$error,
];
}