Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Input/Parser/ErrorMessage.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Client\Input\Parser;
8
9 use eZ\Publish\Core\REST\Common\Input\BaseParser;
10 use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
11 use eZ\Publish\Core\REST\Client\Exceptions\ServerException;
12 use eZ\Publish\Core\REST\Client\Values\ErrorMessage as ErrorMessageValue;
13
17 class ErrorMessage extends BaseParser
18 {
24 protected $errorCodeMapping = array(
25 403 => '\\eZ\\Publish\\Core\\REST\\Common\\Exceptions\\ForbiddenException',
26 404 => '\\eZ\\Publish\\Core\\REST\\Common\\Exceptions\\NotFoundException',
27 406 => '\\eZ\\Publish\\Core\\REST\\Client\\Exceptions\\InvalidArgumentException',
28 409 => '\\eZ\\Publish\\Core\\REST\\Client\\Exceptions\\BadStateException',
29 );
30
39 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
40 {
41 $error = new ErrorMessageValue([
42 'code' => $data['errorCode'],
43 'message' => isset($data['errorMessage']) ? $data['errorMessage'] : null,
44 'description' => isset($data['errorDescription']) ? $data['errorDescription'] : null,
45 'details' => isset($data['errorDetails']) ? $data['errorDetails'] : null,
46 'trace' => isset($data['trace']) ? $data['trace'] : null,
47 'file' => isset($data['file']) ? $data['file'] : null,
48 'line' => isset($data['line']) ? $data['line'] : null,
49 ]);
50
51 // So client behaves closer to api, return relevant exceptions on status codes that maps to them
52 if (isset($this->errorCodeMapping[$data['errorCode']])) {
53 $exceptionClass = $this->errorCodeMapping[$data['errorCode']];
54 return new $exceptionClass($data['errorDescription'], $data['errorCode'], new ServerException($error));
55 }
56
57 return $error;
58 }
59 }
eZ\Publish\Core\REST\Client\Exceptions\ServerException
Wraps a eZ\Publish\Core\REST\Client\Values\ErrorMessage to provide info from server.
Definition: ServerException.php:18
eZ\Publish\Core\REST\Client\Input\Parser\ErrorMessage
Parser for ErrorMessage.
Definition: Input/Parser/ErrorMessage.php:18
eZ\Publish\Core\REST\Client\Input\Parser\ErrorMessage\$errorCodeMapping
$errorCodeMapping
Definition: Input/Parser/ErrorMessage.php:24
eZ\Publish\Core\REST\Client\Input\Parser\ErrorMessage\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parse input structure.
Definition: Input/Parser/ErrorMessage.php:39
eZ\Publish\Core\REST\Client\Values\ErrorMessage
Definition: Values/ErrorMessage.php:20
eZ\Publish\Core\REST\Common\Input\BaseParser
Definition: BaseParser.php:12
eZ\Publish\Core\REST\Common\Input\ParsingDispatcher
Parsing dispatcher.
Definition: ParsingDispatcher.php:15
eZ\Publish\Core\REST\Client\Input\Parser
Definition: Publish/Core/REST/Client/Input/Parser/Content.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.