@@ -112,7 +112,7 @@ |
||
| 112 | 112 | |
| 113 | 113 | $map = static::getMap(); |
| 114 | 114 | |
| 115 | - return $map[ $api_code ] ?? null; |
|
| 115 | + return $map[$api_code] ?? null; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -10,56 +10,56 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | return [ |
| 12 | 12 | |
| 13 | - 'ok' => 'موفق', |
|
| 14 | - 'no_error_message' => 'خطای شماره :api_code', |
|
| 13 | + 'ok' => 'موفق', |
|
| 14 | + 'no_error_message' => 'خطای شماره :api_code', |
|
| 15 | 15 | |
| 16 | - // can be used by Exception Handler (if enabled) |
|
| 17 | - 'uncaught_exception' => 'استثناء مدیریت نشده :message', |
|
| 18 | - // we talking API call here, hence we have http_not_found |
|
| 19 | - 'http_exception' => 'استثناء HTTP :message', |
|
| 16 | + // can be used by Exception Handler (if enabled) |
|
| 17 | + 'uncaught_exception' => 'استثناء مدیریت نشده :message', |
|
| 18 | + // we talking API call here, hence we have http_not_found |
|
| 19 | + 'http_exception' => 'استثناء HTTP :message', |
|
| 20 | 20 | |
| 21 | - // HttpException handler (added in 6.4.0) |
|
| 22 | - // Error messages for HttpException caught w/o custom messages |
|
| 23 | - // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 24 | - 'http_400' => 'Bad Request', |
|
| 25 | - 'http_401' => 'اجازه دسترسی ندارید', |
|
| 26 | - 'http_402' => 'Payment Required', |
|
| 27 | - 'http_403' => 'Forbidden', |
|
| 28 | - 'http_404' => 'Not Found', |
|
| 29 | - 'http_405' => 'Method Not Allowed', |
|
| 30 | - 'http_406' => 'Not Acceptable', |
|
| 31 | - 'http_407' => 'Proxy Authentication Required', |
|
| 32 | - 'http_408' => 'Request Timeout', |
|
| 33 | - 'http_409' => 'Conflict', |
|
| 34 | - 'http_410' => 'Gone', |
|
| 35 | - 'http_411' => 'Length Required', |
|
| 36 | - 'http_412' => 'Precondition Failed', |
|
| 37 | - 'http_413' => 'Payload Too Large', |
|
| 38 | - 'http_414' => 'URI Too Long', |
|
| 39 | - 'http_415' => 'Unsupported Media Type', |
|
| 40 | - 'http_416' => 'Range Not Satisfiable', |
|
| 41 | - 'http_417' => 'Expectation Failed', |
|
| 42 | - 'http_421' => 'Misdirected Request', |
|
| 43 | - 'http_422' => 'داده معتبر نیست', |
|
| 44 | - 'http_423' => 'Locked', |
|
| 45 | - 'http_424' => 'Failed Dependency', |
|
| 46 | - 'http_425' => 'Too Early', |
|
| 47 | - 'http_426' => 'Upgrade Required', |
|
| 48 | - 'http_428' => 'Precondition Required', |
|
| 49 | - 'http_429' => 'Too Many Requests', |
|
| 50 | - 'http_431' => 'Request Header Fields Too Large', |
|
| 51 | - 'http_451' => 'Unavailable For Legal Reasons', |
|
| 52 | - 'http_500' => 'Internal Server Error', |
|
| 53 | - 'http_501' => 'Not Implemented', |
|
| 54 | - 'http_502' => 'Bad Gateway', |
|
| 55 | - 'http_503' => 'Service Unavailable', |
|
| 56 | - 'http_504' => 'Gateway Timeout', |
|
| 57 | - 'http_505' => 'HTTP Version Not Supported', |
|
| 58 | - 'http_506' => 'Variant Also Negotiates', |
|
| 59 | - 'http_507' => 'Insufficient Storage', |
|
| 60 | - 'http_508' => 'Loop Detected', |
|
| 61 | - 'http_509' => 'Unassigned', |
|
| 62 | - 'http_510' => 'Not Extended', |
|
| 63 | - 'http_511' => 'Network Authentication Required', |
|
| 21 | + // HttpException handler (added in 6.4.0) |
|
| 22 | + // Error messages for HttpException caught w/o custom messages |
|
| 23 | + // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 24 | + 'http_400' => 'Bad Request', |
|
| 25 | + 'http_401' => 'اجازه دسترسی ندارید', |
|
| 26 | + 'http_402' => 'Payment Required', |
|
| 27 | + 'http_403' => 'Forbidden', |
|
| 28 | + 'http_404' => 'Not Found', |
|
| 29 | + 'http_405' => 'Method Not Allowed', |
|
| 30 | + 'http_406' => 'Not Acceptable', |
|
| 31 | + 'http_407' => 'Proxy Authentication Required', |
|
| 32 | + 'http_408' => 'Request Timeout', |
|
| 33 | + 'http_409' => 'Conflict', |
|
| 34 | + 'http_410' => 'Gone', |
|
| 35 | + 'http_411' => 'Length Required', |
|
| 36 | + 'http_412' => 'Precondition Failed', |
|
| 37 | + 'http_413' => 'Payload Too Large', |
|
| 38 | + 'http_414' => 'URI Too Long', |
|
| 39 | + 'http_415' => 'Unsupported Media Type', |
|
| 40 | + 'http_416' => 'Range Not Satisfiable', |
|
| 41 | + 'http_417' => 'Expectation Failed', |
|
| 42 | + 'http_421' => 'Misdirected Request', |
|
| 43 | + 'http_422' => 'داده معتبر نیست', |
|
| 44 | + 'http_423' => 'Locked', |
|
| 45 | + 'http_424' => 'Failed Dependency', |
|
| 46 | + 'http_425' => 'Too Early', |
|
| 47 | + 'http_426' => 'Upgrade Required', |
|
| 48 | + 'http_428' => 'Precondition Required', |
|
| 49 | + 'http_429' => 'Too Many Requests', |
|
| 50 | + 'http_431' => 'Request Header Fields Too Large', |
|
| 51 | + 'http_451' => 'Unavailable For Legal Reasons', |
|
| 52 | + 'http_500' => 'Internal Server Error', |
|
| 53 | + 'http_501' => 'Not Implemented', |
|
| 54 | + 'http_502' => 'Bad Gateway', |
|
| 55 | + 'http_503' => 'Service Unavailable', |
|
| 56 | + 'http_504' => 'Gateway Timeout', |
|
| 57 | + 'http_505' => 'HTTP Version Not Supported', |
|
| 58 | + 'http_506' => 'Variant Also Negotiates', |
|
| 59 | + 'http_507' => 'Insufficient Storage', |
|
| 60 | + 'http_508' => 'Loop Detected', |
|
| 61 | + 'http_509' => 'Unassigned', |
|
| 62 | + 'http_510' => 'Not Extended', |
|
| 63 | + 'http_511' => 'Network Authentication Required', |
|
| 64 | 64 | ]; |
| 65 | 65 | |
@@ -21,172 +21,172 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class BaseApiCodes |
| 23 | 23 | { |
| 24 | - use ApiCodesHelpers; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * protected code range - lowest code for reserved range. |
|
| 28 | - * |
|
| 29 | - * @var int |
|
| 30 | - */ |
|
| 31 | - public const RESERVED_MIN_API_CODE_OFFSET = 0; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * protected code range - highest code for reserved range |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - public const RESERVED_MAX_API_CODE_OFFSET = 19; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * built-in codes: OK |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected const OK_OFFSET = 0; |
|
| 46 | - /** |
|
| 47 | - * built-in code for fallback message mapping |
|
| 48 | - * |
|
| 49 | - * @var int |
|
| 50 | - */ |
|
| 51 | - protected const NO_ERROR_MESSAGE_OFFSET = 1; |
|
| 52 | - /** |
|
| 53 | - * built-in error code for HTTP_NOT_FOUND exception |
|
| 54 | - * |
|
| 55 | - * @var int |
|
| 56 | - */ |
|
| 57 | - protected const EX_HTTP_NOT_FOUND_OFFSET = 10; |
|
| 58 | - /** |
|
| 59 | - * built-in error code for HTTP_SERVICE_UNAVAILABLE exception |
|
| 60 | - * |
|
| 61 | - * @var int |
|
| 62 | - */ |
|
| 63 | - protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11; |
|
| 64 | - /** |
|
| 65 | - * built-in error code for HTTP_EXCEPTION |
|
| 66 | - * |
|
| 67 | - * @var int |
|
| 68 | - */ |
|
| 69 | - protected const EX_HTTP_EXCEPTION_OFFSET = 12; |
|
| 70 | - /** |
|
| 71 | - * built-in error code for UNCAUGHT_EXCEPTION |
|
| 72 | - * |
|
| 73 | - * @var int |
|
| 74 | - */ |
|
| 75 | - protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 79 | - * |
|
| 80 | - * @var int |
|
| 81 | - */ |
|
| 82 | - protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - protected const EX_VALIDATION_EXCEPTION_OFFSET = 15; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Returns base code mapping array |
|
| 93 | - * |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - protected static function getBaseMap(): array |
|
| 97 | - { |
|
| 98 | - $tpl = 'response-builder::builder.http_%d'; |
|
| 99 | - |
|
| 100 | - return [ |
|
| 101 | - self::OK() => 'response-builder::builder.ok', |
|
| 102 | - self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
| 103 | - self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
| 104 | - self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
| 105 | - self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
| 106 | - self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
| 107 | - self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
| 108 | - self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
| 109 | - ]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns API code for internal code OK |
|
| 114 | - * |
|
| 115 | - * @return int valid API code in current range |
|
| 116 | - */ |
|
| 117 | - public static function OK(): int |
|
| 118 | - { |
|
| 119 | - return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Returns API code for internal code NO_ERROR_MESSAGE |
|
| 124 | - * |
|
| 125 | - * @return int valid API code in current range |
|
| 126 | - */ |
|
| 127 | - public static function NO_ERROR_MESSAGE(): int |
|
| 128 | - { |
|
| 129 | - return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Returns API code for internal code EX_HTTP_NOT_FOUND |
|
| 134 | - * |
|
| 135 | - * @return int valid API code in current range |
|
| 136 | - */ |
|
| 137 | - public static function EX_HTTP_NOT_FOUND(): int |
|
| 138 | - { |
|
| 139 | - return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Returns API code for internal code EX_HTTP_EXCEPTION |
|
| 144 | - * |
|
| 145 | - * @return int valid API code in current range |
|
| 146 | - */ |
|
| 147 | - public static function EX_HTTP_EXCEPTION(): int |
|
| 148 | - { |
|
| 149 | - return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
|
| 154 | - * |
|
| 155 | - * @return int valid API code in current range |
|
| 156 | - */ |
|
| 157 | - public static function EX_UNCAUGHT_EXCEPTION(): int |
|
| 158 | - { |
|
| 159 | - return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
|
| 164 | - * |
|
| 165 | - * @return int valid API code in current range |
|
| 166 | - */ |
|
| 167 | - public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
| 168 | - { |
|
| 169 | - return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Returns API code for internal code EX_VALIDATION_EXCEPTION |
|
| 174 | - * |
|
| 175 | - * @return int valid API code in current range |
|
| 176 | - */ |
|
| 177 | - public static function EX_VALIDATION_EXCEPTION(): int |
|
| 178 | - { |
|
| 179 | - return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
|
| 184 | - * |
|
| 185 | - * @return int valid API code in current range |
|
| 186 | - */ |
|
| 187 | - public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
| 188 | - { |
|
| 189 | - return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
| 190 | - } |
|
| 24 | + use ApiCodesHelpers; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * protected code range - lowest code for reserved range. |
|
| 28 | + * |
|
| 29 | + * @var int |
|
| 30 | + */ |
|
| 31 | + public const RESERVED_MIN_API_CODE_OFFSET = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * protected code range - highest code for reserved range |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + public const RESERVED_MAX_API_CODE_OFFSET = 19; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * built-in codes: OK |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected const OK_OFFSET = 0; |
|
| 46 | + /** |
|
| 47 | + * built-in code for fallback message mapping |
|
| 48 | + * |
|
| 49 | + * @var int |
|
| 50 | + */ |
|
| 51 | + protected const NO_ERROR_MESSAGE_OFFSET = 1; |
|
| 52 | + /** |
|
| 53 | + * built-in error code for HTTP_NOT_FOUND exception |
|
| 54 | + * |
|
| 55 | + * @var int |
|
| 56 | + */ |
|
| 57 | + protected const EX_HTTP_NOT_FOUND_OFFSET = 10; |
|
| 58 | + /** |
|
| 59 | + * built-in error code for HTTP_SERVICE_UNAVAILABLE exception |
|
| 60 | + * |
|
| 61 | + * @var int |
|
| 62 | + */ |
|
| 63 | + protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11; |
|
| 64 | + /** |
|
| 65 | + * built-in error code for HTTP_EXCEPTION |
|
| 66 | + * |
|
| 67 | + * @var int |
|
| 68 | + */ |
|
| 69 | + protected const EX_HTTP_EXCEPTION_OFFSET = 12; |
|
| 70 | + /** |
|
| 71 | + * built-in error code for UNCAUGHT_EXCEPTION |
|
| 72 | + * |
|
| 73 | + * @var int |
|
| 74 | + */ |
|
| 75 | + protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 79 | + * |
|
| 80 | + * @var int |
|
| 81 | + */ |
|
| 82 | + protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + protected const EX_VALIDATION_EXCEPTION_OFFSET = 15; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Returns base code mapping array |
|
| 93 | + * |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + protected static function getBaseMap(): array |
|
| 97 | + { |
|
| 98 | + $tpl = 'response-builder::builder.http_%d'; |
|
| 99 | + |
|
| 100 | + return [ |
|
| 101 | + self::OK() => 'response-builder::builder.ok', |
|
| 102 | + self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
| 103 | + self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
| 104 | + self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
| 105 | + self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
| 106 | + self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
| 107 | + self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
| 108 | + self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
| 109 | + ]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns API code for internal code OK |
|
| 114 | + * |
|
| 115 | + * @return int valid API code in current range |
|
| 116 | + */ |
|
| 117 | + public static function OK(): int |
|
| 118 | + { |
|
| 119 | + return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Returns API code for internal code NO_ERROR_MESSAGE |
|
| 124 | + * |
|
| 125 | + * @return int valid API code in current range |
|
| 126 | + */ |
|
| 127 | + public static function NO_ERROR_MESSAGE(): int |
|
| 128 | + { |
|
| 129 | + return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Returns API code for internal code EX_HTTP_NOT_FOUND |
|
| 134 | + * |
|
| 135 | + * @return int valid API code in current range |
|
| 136 | + */ |
|
| 137 | + public static function EX_HTTP_NOT_FOUND(): int |
|
| 138 | + { |
|
| 139 | + return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Returns API code for internal code EX_HTTP_EXCEPTION |
|
| 144 | + * |
|
| 145 | + * @return int valid API code in current range |
|
| 146 | + */ |
|
| 147 | + public static function EX_HTTP_EXCEPTION(): int |
|
| 148 | + { |
|
| 149 | + return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
|
| 154 | + * |
|
| 155 | + * @return int valid API code in current range |
|
| 156 | + */ |
|
| 157 | + public static function EX_UNCAUGHT_EXCEPTION(): int |
|
| 158 | + { |
|
| 159 | + return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
|
| 164 | + * |
|
| 165 | + * @return int valid API code in current range |
|
| 166 | + */ |
|
| 167 | + public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
| 168 | + { |
|
| 169 | + return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Returns API code for internal code EX_VALIDATION_EXCEPTION |
|
| 174 | + * |
|
| 175 | + * @return int valid API code in current range |
|
| 176 | + */ |
|
| 177 | + public static function EX_VALIDATION_EXCEPTION(): int |
|
| 178 | + { |
|
| 179 | + return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
|
| 184 | + * |
|
| 185 | + * @return int valid API code in current range |
|
| 186 | + */ |
|
| 187 | + public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
| 188 | + { |
|
| 189 | + return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @return \Symfony\Component\HttpFoundation\Response |
| 73 | 73 | */ |
| 74 | 74 | protected static function processException(\Exception $ex, array $ex_cfg, |
| 75 | - int $fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR) |
|
| 75 | + int $fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR) |
|
| 76 | 76 | { |
| 77 | 77 | $api_code = $ex_cfg['api_code']; |
| 78 | 78 | $http_code = $ex_cfg['http_code'] ?? $fallback_http_code; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @return HttpResponse |
| 142 | 142 | */ |
| 143 | 143 | protected function unauthenticated(/** @scrutinizer ignore-unused */ $request, |
| 144 | - AuthException $exception): HttpResponse |
|
| 144 | + AuthException $exception): HttpResponse |
|
| 145 | 145 | { |
| 146 | 146 | $cfg = self::getExceptionHandlerConfig(); |
| 147 | 147 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @return HttpResponse |
| 163 | 163 | */ |
| 164 | 164 | protected static function error(Exception $ex, |
| 165 | - int $api_code, int $http_code = null, string $error_message = null): HttpResponse |
|
| 165 | + int $api_code, int $http_code = null, string $error_message = null): HttpResponse |
|
| 166 | 166 | { |
| 167 | 167 | $ex_http_code = ($ex instanceof HttpException) ? $ex->getStatusCode() : $ex->getCode(); |
| 168 | 168 | $http_code = $http_code ?? $ex_http_code; |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | do { |
| 46 | 46 | if ($cfg === null) { |
| 47 | 47 | // Default handler MUST be present by design and always return something useful. |
| 48 | - $cfg = self::getExceptionHandlerConfig()[ RB::KEY_DEFAULT ]; |
|
| 48 | + $cfg = self::getExceptionHandlerConfig()[RB::KEY_DEFAULT]; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $handler = new $cfg[ RB::KEY_HANDLER ](); |
|
| 52 | - $handler_result = $handler->handle($cfg[ RB::KEY_CONFIG ], $ex); |
|
| 51 | + $handler = new $cfg[RB::KEY_HANDLER](); |
|
| 52 | + $handler_result = $handler->handle($cfg[RB::KEY_CONFIG], $ex); |
|
| 53 | 53 | if ($handler_result !== null) { |
| 54 | 54 | $result = self::processException($ex, $handler_result); |
| 55 | 55 | } else { |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $cfg = self::getExceptionHandlerConfig(); |
| 148 | 148 | |
| 149 | 149 | // This config entry is guaranted to exist. Enforced by tests. |
| 150 | - $cfg = $cfg[ HttpException::class ][ RB::KEY_CONFIG ][ HttpResponse::HTTP_UNAUTHORIZED ]; |
|
| 150 | + $cfg = $cfg[HttpException::class][RB::KEY_CONFIG][HttpResponse::HTTP_UNAUTHORIZED]; |
|
| 151 | 151 | |
| 152 | 152 | return static::processException($exception, $cfg, HttpResponse::HTTP_UNAUTHORIZED); |
| 153 | 153 | } |
@@ -277,13 +277,13 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | // check for exact class name match... |
| 279 | 279 | if (\array_key_exists($cls, $cfg)) { |
| 280 | - $result = $cfg[ $cls ]; |
|
| 280 | + $result = $cfg[$cls]; |
|
| 281 | 281 | } else { |
| 282 | 282 | // no exact match, then lets try with `instanceof` |
| 283 | 283 | // Config entries are already sorted by priority. |
| 284 | 284 | foreach (\array_keys($cfg) as $class_name) { |
| 285 | 285 | if ($ex instanceof $class_name) { |
| 286 | - $result = $cfg[ $class_name ]; |
|
| 286 | + $result = $cfg[$class_name]; |
|
| 287 | 287 | break; |
| 288 | 288 | } |
| 289 | 289 | } |
@@ -10,58 +10,58 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | return [ |
| 12 | 12 | |
| 13 | - 'ok' => 'OK', |
|
| 14 | - 'no_error_message' => 'Fehler #:api_code', |
|
| 13 | + 'ok' => 'OK', |
|
| 14 | + 'no_error_message' => 'Fehler #:api_code', |
|
| 15 | 15 | |
| 16 | - // Used by Exception Handler Helper (when used) |
|
| 17 | - 'uncaught_exception' => 'Ungefangene Ausnahme: :message', |
|
| 18 | - 'http_exception' => 'HTTP Ausnahme: :message', |
|
| 16 | + // Used by Exception Handler Helper (when used) |
|
| 17 | + 'uncaught_exception' => 'Ungefangene Ausnahme: :message', |
|
| 18 | + 'http_exception' => 'HTTP Ausnahme: :message', |
|
| 19 | 19 | |
| 20 | - // HttpException handler (added in 6.4.0) |
|
| 21 | - // Error messages for HttpException caught w/o custom messages |
|
| 22 | - // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 23 | - // |
|
| 24 | - // German translation based on https://wiki.selfhtml.org/wiki/HTTP/Statuscodes |
|
| 25 | - 'http_400' => 'Ungültige Anfrage', |
|
| 26 | - 'http_401' => 'Unautorisiert', |
|
| 27 | - 'http_402' => 'Bezahlung benötigt', |
|
| 28 | - 'http_403' => 'Verboten', |
|
| 29 | - 'http_404' => 'Nicht gefunden', |
|
| 30 | - 'http_405' => 'Methode nicht erlaubt', |
|
| 31 | - 'http_406' => 'Nicht akzeptabel', |
|
| 32 | - 'http_407' => 'Proxy-Authentifizierung benötigt', |
|
| 33 | - 'http_408' => 'Anfrage-Zeitüberschreitung', |
|
| 34 | - 'http_409' => 'Konflikt', |
|
| 35 | - 'http_410' => 'Verschwunden', |
|
| 36 | - 'http_411' => 'Länge benötigt', |
|
| 37 | - 'http_412' => 'Vorbedingung missglückt', |
|
| 38 | - 'http_413' => 'Anfrage-Entität zu groß', |
|
| 39 | - 'http_414' => 'Anfrage-URI zu lang', |
|
| 40 | - 'http_415' => 'Nicht unterstützter Medientyp', |
|
| 41 | - 'http_416' => 'Anfrage-Bereich nicht erfüllbar', |
|
| 42 | - 'http_417' => 'Erwartung missglückt', |
|
| 43 | - 'http_421' => 'Fehlgeleitete Anforderung', |
|
| 44 | - 'http_422' => 'Kann nicht verarbeitet werden', |
|
| 45 | - 'http_423' => 'Gesperrt', |
|
| 46 | - 'http_424' => 'Vorhergehende Bedingung nicht erfüllt', |
|
| 47 | - 'http_425' => 'Too Early', // FIXME |
|
| 48 | - 'http_426' => 'Update benötigt', |
|
| 49 | - 'http_428' => ' Vorbedingung benötigt', |
|
| 50 | - 'http_429' => 'Zu viele Anfragen', |
|
| 51 | - 'http_431' => 'Headerfelds zu groß', |
|
| 52 | - 'http_451' => 'Ressource aus rechtlichen Gründen nicht verfügbar', |
|
| 20 | + // HttpException handler (added in 6.4.0) |
|
| 21 | + // Error messages for HttpException caught w/o custom messages |
|
| 22 | + // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 23 | + // |
|
| 24 | + // German translation based on https://wiki.selfhtml.org/wiki/HTTP/Statuscodes |
|
| 25 | + 'http_400' => 'Ungültige Anfrage', |
|
| 26 | + 'http_401' => 'Unautorisiert', |
|
| 27 | + 'http_402' => 'Bezahlung benötigt', |
|
| 28 | + 'http_403' => 'Verboten', |
|
| 29 | + 'http_404' => 'Nicht gefunden', |
|
| 30 | + 'http_405' => 'Methode nicht erlaubt', |
|
| 31 | + 'http_406' => 'Nicht akzeptabel', |
|
| 32 | + 'http_407' => 'Proxy-Authentifizierung benötigt', |
|
| 33 | + 'http_408' => 'Anfrage-Zeitüberschreitung', |
|
| 34 | + 'http_409' => 'Konflikt', |
|
| 35 | + 'http_410' => 'Verschwunden', |
|
| 36 | + 'http_411' => 'Länge benötigt', |
|
| 37 | + 'http_412' => 'Vorbedingung missglückt', |
|
| 38 | + 'http_413' => 'Anfrage-Entität zu groß', |
|
| 39 | + 'http_414' => 'Anfrage-URI zu lang', |
|
| 40 | + 'http_415' => 'Nicht unterstützter Medientyp', |
|
| 41 | + 'http_416' => 'Anfrage-Bereich nicht erfüllbar', |
|
| 42 | + 'http_417' => 'Erwartung missglückt', |
|
| 43 | + 'http_421' => 'Fehlgeleitete Anforderung', |
|
| 44 | + 'http_422' => 'Kann nicht verarbeitet werden', |
|
| 45 | + 'http_423' => 'Gesperrt', |
|
| 46 | + 'http_424' => 'Vorhergehende Bedingung nicht erfüllt', |
|
| 47 | + 'http_425' => 'Too Early', // FIXME |
|
| 48 | + 'http_426' => 'Update benötigt', |
|
| 49 | + 'http_428' => ' Vorbedingung benötigt', |
|
| 50 | + 'http_429' => 'Zu viele Anfragen', |
|
| 51 | + 'http_431' => 'Headerfelds zu groß', |
|
| 52 | + 'http_451' => 'Ressource aus rechtlichen Gründen nicht verfügbar', |
|
| 53 | 53 | |
| 54 | - 'http_500' => 'Interner Server-Fehler', |
|
| 55 | - 'http_501' => 'Nicht implementiert', |
|
| 56 | - 'http_502' => 'Schlechtes Portal', |
|
| 57 | - 'http_503' => 'Dienst nicht verfügbar', |
|
| 58 | - 'http_504' => 'Portal-Auszeit', |
|
| 59 | - 'http_505' => 'HTTP-Version nicht unterstützt', |
|
| 60 | - 'http_506' => 'Variant Also Negotiates', // FIXME |
|
| 61 | - 'http_507' => 'Speicher des Servers reicht nicht aus', |
|
| 62 | - 'http_508' => 'Endlosschleife', |
|
| 63 | - 'http_509' => 'Unassigned', // FIXME |
|
| 64 | - 'http_510' => 'Zu wenig Informationen', |
|
| 65 | - 'http_511' => 'Identizifierung benötigt', |
|
| 54 | + 'http_500' => 'Interner Server-Fehler', |
|
| 55 | + 'http_501' => 'Nicht implementiert', |
|
| 56 | + 'http_502' => 'Schlechtes Portal', |
|
| 57 | + 'http_503' => 'Dienst nicht verfügbar', |
|
| 58 | + 'http_504' => 'Portal-Auszeit', |
|
| 59 | + 'http_505' => 'HTTP-Version nicht unterstützt', |
|
| 60 | + 'http_506' => 'Variant Also Negotiates', // FIXME |
|
| 61 | + 'http_507' => 'Speicher des Servers reicht nicht aus', |
|
| 62 | + 'http_508' => 'Endlosschleife', |
|
| 63 | + 'http_509' => 'Unassigned', // FIXME |
|
| 64 | + 'http_510' => 'Zu wenig Informationen', |
|
| 65 | + 'http_511' => 'Identizifierung benötigt', |
|
| 66 | 66 | ]; |
| 67 | 67 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | 'http_422' => 'Kann nicht verarbeitet werden', |
| 45 | 45 | 'http_423' => 'Gesperrt', |
| 46 | 46 | 'http_424' => 'Vorhergehende Bedingung nicht erfüllt', |
| 47 | - 'http_425' => 'Too Early', // FIXME |
|
| 47 | + 'http_425' => 'Too Early', // FIXME |
|
| 48 | 48 | 'http_426' => 'Update benötigt', |
| 49 | 49 | 'http_428' => ' Vorbedingung benötigt', |
| 50 | 50 | 'http_429' => 'Zu viele Anfragen', |
@@ -57,10 +57,10 @@ discard block |
||
| 57 | 57 | 'http_503' => 'Dienst nicht verfügbar', |
| 58 | 58 | 'http_504' => 'Portal-Auszeit', |
| 59 | 59 | 'http_505' => 'HTTP-Version nicht unterstützt', |
| 60 | - 'http_506' => 'Variant Also Negotiates', // FIXME |
|
| 60 | + 'http_506' => 'Variant Also Negotiates', // FIXME |
|
| 61 | 61 | 'http_507' => 'Speicher des Servers reicht nicht aus', |
| 62 | 62 | 'http_508' => 'Endlosschleife', |
| 63 | - 'http_509' => 'Unassigned', // FIXME |
|
| 63 | + 'http_509' => 'Unassigned', // FIXME |
|
| 64 | 64 | 'http_510' => 'Zu wenig Informationen', |
| 65 | 65 | 'http_511' => 'Identizifierung benötigt', |
| 66 | 66 | ]; |
@@ -10,56 +10,56 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | return [ |
| 12 | 12 | |
| 13 | - 'ok' => 'OK', |
|
| 14 | - 'no_error_message' => 'Error #:api_code', |
|
| 13 | + 'ok' => 'OK', |
|
| 14 | + 'no_error_message' => 'Error #:api_code', |
|
| 15 | 15 | |
| 16 | - // Used by Exception Handler Helper (when used) |
|
| 17 | - 'uncaught_exception' => 'Uncaught exception: :message', |
|
| 18 | - 'http_exception' => 'HTTP exception: :message', |
|
| 16 | + // Used by Exception Handler Helper (when used) |
|
| 17 | + 'uncaught_exception' => 'Uncaught exception: :message', |
|
| 18 | + 'http_exception' => 'HTTP exception: :message', |
|
| 19 | 19 | |
| 20 | - // HttpException handler (added in 6.4.0) |
|
| 21 | - // Error messages for HttpException caught w/o custom messages |
|
| 22 | - // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 23 | - 'http_400' => 'Bad Request', |
|
| 24 | - 'http_401' => 'Unauthorized', |
|
| 25 | - 'http_402' => 'Payment Required', |
|
| 26 | - 'http_403' => 'Forbidden', |
|
| 27 | - 'http_404' => 'Not Found', |
|
| 28 | - 'http_405' => 'Method Not Allowed', |
|
| 29 | - 'http_406' => 'Not Acceptable', |
|
| 30 | - 'http_407' => 'Proxy Authentication Required', |
|
| 31 | - 'http_408' => 'Request Timeout', |
|
| 32 | - 'http_409' => 'Conflict', |
|
| 33 | - 'http_410' => 'Gone', |
|
| 34 | - 'http_411' => 'Length Required', |
|
| 35 | - 'http_412' => 'Precondition Failed', |
|
| 36 | - 'http_413' => 'Payload Too Large', |
|
| 37 | - 'http_414' => 'URI Too Long', |
|
| 38 | - 'http_415' => 'Unsupported Media Type', |
|
| 39 | - 'http_416' => 'Range Not Satisfiable', |
|
| 40 | - 'http_417' => 'Expectation Failed', |
|
| 41 | - 'http_421' => 'Misdirected Request', |
|
| 42 | - 'http_422' => 'Unprocessable Entity', |
|
| 43 | - 'http_423' => 'Locked', |
|
| 44 | - 'http_424' => 'Failed Dependency', |
|
| 45 | - 'http_425' => 'Too Early', |
|
| 46 | - 'http_426' => 'Upgrade Required', |
|
| 47 | - 'http_428' => 'Precondition Required', |
|
| 48 | - 'http_429' => 'Too Many Requests', |
|
| 49 | - 'http_431' => 'Request Header Fields Too Large', |
|
| 50 | - 'http_451' => 'Unavailable For Legal Reasons', |
|
| 20 | + // HttpException handler (added in 6.4.0) |
|
| 21 | + // Error messages for HttpException caught w/o custom messages |
|
| 22 | + // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 23 | + 'http_400' => 'Bad Request', |
|
| 24 | + 'http_401' => 'Unauthorized', |
|
| 25 | + 'http_402' => 'Payment Required', |
|
| 26 | + 'http_403' => 'Forbidden', |
|
| 27 | + 'http_404' => 'Not Found', |
|
| 28 | + 'http_405' => 'Method Not Allowed', |
|
| 29 | + 'http_406' => 'Not Acceptable', |
|
| 30 | + 'http_407' => 'Proxy Authentication Required', |
|
| 31 | + 'http_408' => 'Request Timeout', |
|
| 32 | + 'http_409' => 'Conflict', |
|
| 33 | + 'http_410' => 'Gone', |
|
| 34 | + 'http_411' => 'Length Required', |
|
| 35 | + 'http_412' => 'Precondition Failed', |
|
| 36 | + 'http_413' => 'Payload Too Large', |
|
| 37 | + 'http_414' => 'URI Too Long', |
|
| 38 | + 'http_415' => 'Unsupported Media Type', |
|
| 39 | + 'http_416' => 'Range Not Satisfiable', |
|
| 40 | + 'http_417' => 'Expectation Failed', |
|
| 41 | + 'http_421' => 'Misdirected Request', |
|
| 42 | + 'http_422' => 'Unprocessable Entity', |
|
| 43 | + 'http_423' => 'Locked', |
|
| 44 | + 'http_424' => 'Failed Dependency', |
|
| 45 | + 'http_425' => 'Too Early', |
|
| 46 | + 'http_426' => 'Upgrade Required', |
|
| 47 | + 'http_428' => 'Precondition Required', |
|
| 48 | + 'http_429' => 'Too Many Requests', |
|
| 49 | + 'http_431' => 'Request Header Fields Too Large', |
|
| 50 | + 'http_451' => 'Unavailable For Legal Reasons', |
|
| 51 | 51 | |
| 52 | - 'http_500' => 'Internal Server Error', |
|
| 53 | - 'http_501' => 'Not Implemented', |
|
| 54 | - 'http_502' => 'Bad Gateway', |
|
| 55 | - 'http_503' => 'Service Unavailable', |
|
| 56 | - 'http_504' => 'Gateway Timeout', |
|
| 57 | - 'http_505' => 'HTTP Version Not Supported', |
|
| 58 | - 'http_506' => 'Variant Also Negotiates', |
|
| 59 | - 'http_507' => 'Insufficient Storage', |
|
| 60 | - 'http_508' => 'Loop Detected', |
|
| 61 | - 'http_509' => 'Unassigned', |
|
| 62 | - 'http_510' => 'Not Extended', |
|
| 63 | - 'http_511' => 'Network Authentication Required', |
|
| 52 | + 'http_500' => 'Internal Server Error', |
|
| 53 | + 'http_501' => 'Not Implemented', |
|
| 54 | + 'http_502' => 'Bad Gateway', |
|
| 55 | + 'http_503' => 'Service Unavailable', |
|
| 56 | + 'http_504' => 'Gateway Timeout', |
|
| 57 | + 'http_505' => 'HTTP Version Not Supported', |
|
| 58 | + 'http_506' => 'Variant Also Negotiates', |
|
| 59 | + 'http_507' => 'Insufficient Storage', |
|
| 60 | + 'http_508' => 'Loop Detected', |
|
| 61 | + 'http_509' => 'Unassigned', |
|
| 62 | + 'http_510' => 'Not Extended', |
|
| 63 | + 'http_511' => 'Network Authentication Required', |
|
| 64 | 64 | ]; |
| 65 | 65 | |
@@ -10,55 +10,55 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | return [ |
| 12 | 12 | |
| 13 | - 'ok' => 'OK', |
|
| 14 | - 'no_error_message' => 'Błąd #:api_code', |
|
| 13 | + 'ok' => 'OK', |
|
| 14 | + 'no_error_message' => 'Błąd #:api_code', |
|
| 15 | 15 | |
| 16 | - // Used by Exception Handler Helper (when used) |
|
| 17 | - 'uncaught_exception' => 'Nieprzechwycony wyjątek: :message', |
|
| 18 | - 'http_exception' => 'Wyjątek HTTP: :message', |
|
| 16 | + // Used by Exception Handler Helper (when used) |
|
| 17 | + 'uncaught_exception' => 'Nieprzechwycony wyjątek: :message', |
|
| 18 | + 'http_exception' => 'Wyjątek HTTP: :message', |
|
| 19 | 19 | |
| 20 | - // HttpException handler (added in 6.4.0) |
|
| 21 | - // Error messages for HttpException caught w/o custom messages |
|
| 22 | - // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 23 | - 'http_400' => 'Bad Request', |
|
| 24 | - 'http_401' => 'Unauthorized', |
|
| 25 | - 'http_402' => 'Payment Required', |
|
| 26 | - 'http_403' => 'Forbidden', |
|
| 27 | - 'http_404' => 'Not Found', |
|
| 28 | - 'http_405' => 'Method Not Allowed', |
|
| 29 | - 'http_406' => 'Not Acceptable', |
|
| 30 | - 'http_407' => 'Proxy Authentication Required', |
|
| 31 | - 'http_408' => 'Request Timeout', |
|
| 32 | - 'http_409' => 'Conflict', |
|
| 33 | - 'http_410' => 'Gone', |
|
| 34 | - 'http_411' => 'Length Required', |
|
| 35 | - 'http_412' => 'Precondition Failed', |
|
| 36 | - 'http_413' => 'Payload Too Large', |
|
| 37 | - 'http_414' => 'URI Too Long', |
|
| 38 | - 'http_415' => 'Unsupported Media Type', |
|
| 39 | - 'http_416' => 'Range Not Satisfiable', |
|
| 40 | - 'http_417' => 'Expectation Failed', |
|
| 41 | - 'http_421' => 'Misdirected Request', |
|
| 42 | - 'http_422' => 'Unprocessable Entity', |
|
| 43 | - 'http_423' => 'Locked', |
|
| 44 | - 'http_424' => 'Failed Dependency', |
|
| 45 | - 'http_425' => 'Too Early', |
|
| 46 | - 'http_426' => 'Upgrade Required', |
|
| 47 | - 'http_428' => 'Precondition Required', |
|
| 48 | - 'http_429' => 'Too Many Requests', |
|
| 49 | - 'http_431' => 'Request Header Fields Too Large', |
|
| 50 | - 'http_451' => 'Unavailable For Legal Reasons', |
|
| 20 | + // HttpException handler (added in 6.4.0) |
|
| 21 | + // Error messages for HttpException caught w/o custom messages |
|
| 22 | + // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
| 23 | + 'http_400' => 'Bad Request', |
|
| 24 | + 'http_401' => 'Unauthorized', |
|
| 25 | + 'http_402' => 'Payment Required', |
|
| 26 | + 'http_403' => 'Forbidden', |
|
| 27 | + 'http_404' => 'Not Found', |
|
| 28 | + 'http_405' => 'Method Not Allowed', |
|
| 29 | + 'http_406' => 'Not Acceptable', |
|
| 30 | + 'http_407' => 'Proxy Authentication Required', |
|
| 31 | + 'http_408' => 'Request Timeout', |
|
| 32 | + 'http_409' => 'Conflict', |
|
| 33 | + 'http_410' => 'Gone', |
|
| 34 | + 'http_411' => 'Length Required', |
|
| 35 | + 'http_412' => 'Precondition Failed', |
|
| 36 | + 'http_413' => 'Payload Too Large', |
|
| 37 | + 'http_414' => 'URI Too Long', |
|
| 38 | + 'http_415' => 'Unsupported Media Type', |
|
| 39 | + 'http_416' => 'Range Not Satisfiable', |
|
| 40 | + 'http_417' => 'Expectation Failed', |
|
| 41 | + 'http_421' => 'Misdirected Request', |
|
| 42 | + 'http_422' => 'Unprocessable Entity', |
|
| 43 | + 'http_423' => 'Locked', |
|
| 44 | + 'http_424' => 'Failed Dependency', |
|
| 45 | + 'http_425' => 'Too Early', |
|
| 46 | + 'http_426' => 'Upgrade Required', |
|
| 47 | + 'http_428' => 'Precondition Required', |
|
| 48 | + 'http_429' => 'Too Many Requests', |
|
| 49 | + 'http_431' => 'Request Header Fields Too Large', |
|
| 50 | + 'http_451' => 'Unavailable For Legal Reasons', |
|
| 51 | 51 | |
| 52 | - 'http_500' => 'Internal Server Error', |
|
| 53 | - 'http_501' => 'Not Implemented', |
|
| 54 | - 'http_502' => 'Bad Gateway', |
|
| 55 | - 'http_503' => 'Service Unavailable', |
|
| 56 | - 'http_504' => 'Gateway Timeout', |
|
| 57 | - 'http_505' => 'HTTP Version Not Supported', |
|
| 58 | - 'http_506' => 'Variant Also Negotiates', |
|
| 59 | - 'http_507' => 'Insufficient Storage', |
|
| 60 | - 'http_508' => 'Loop Detected', |
|
| 61 | - 'http_509' => 'Unassigned', |
|
| 62 | - 'http_510' => 'Not Extended', |
|
| 63 | - 'http_511' => 'Network Authentication Required', |
|
| 52 | + 'http_500' => 'Internal Server Error', |
|
| 53 | + 'http_501' => 'Not Implemented', |
|
| 54 | + 'http_502' => 'Bad Gateway', |
|
| 55 | + 'http_503' => 'Service Unavailable', |
|
| 56 | + 'http_504' => 'Gateway Timeout', |
|
| 57 | + 'http_505' => 'HTTP Version Not Supported', |
|
| 58 | + 'http_506' => 'Variant Also Negotiates', |
|
| 59 | + 'http_507' => 'Insufficient Storage', |
|
| 60 | + 'http_508' => 'Loop Detected', |
|
| 61 | + 'http_509' => 'Unassigned', |
|
| 62 | + 'http_510' => 'Not Extended', |
|
| 63 | + 'http_511' => 'Network Authentication Required', |
|
| 64 | 64 | ]; |
@@ -12,100 +12,100 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | return [ |
| 15 | - /* |
|
| 15 | + /* |
|
| 16 | 16 | |----------------------------------------------------------------------------------------------------------- |
| 17 | 17 | | Code range settings |
| 18 | 18 | |----------------------------------------------------------------------------------------------------------- |
| 19 | 19 | */ |
| 20 | - 'min_code' => 100, |
|
| 21 | - 'max_code' => 1024, |
|
| 20 | + 'min_code' => 100, |
|
| 21 | + 'max_code' => 1024, |
|
| 22 | 22 | |
| 23 | - /* |
|
| 23 | + /* |
|
| 24 | 24 | |----------------------------------------------------------------------------------------------------------- |
| 25 | 25 | | Error code to message mapping |
| 26 | 26 | |----------------------------------------------------------------------------------------------------------- |
| 27 | 27 | | |
| 28 | 28 | */ |
| 29 | - 'map' => [ |
|
| 30 | - // YOUR_API_CODE => '<MESSAGE_KEY>', |
|
| 31 | - ], |
|
| 29 | + 'map' => [ |
|
| 30 | + // YOUR_API_CODE => '<MESSAGE_KEY>', |
|
| 31 | + ], |
|
| 32 | 32 | |
| 33 | - /* |
|
| 33 | + /* |
|
| 34 | 34 | |----------------------------------------------------------------------------------------------------------- |
| 35 | 35 | | Response Builder data converter |
| 36 | 36 | |----------------------------------------------------------------------------------------------------------- |
| 37 | 37 | | |
| 38 | 38 | */ |
| 39 | - 'converter' => [ |
|
| 40 | - 'primitives' => [ |
|
| 41 | - /* Configuration for primitives used when such data is passed directly as payload (i.e. `success(15)`;) */ |
|
| 42 | - 'array' => [ |
|
| 43 | - 'key' => 'values', |
|
| 44 | - ], |
|
| 45 | - 'boolean' => [ |
|
| 46 | - 'key' => 'value', |
|
| 47 | - ], |
|
| 48 | - 'double' => [ |
|
| 49 | - 'key' => 'value', |
|
| 50 | - ], |
|
| 51 | - 'integer' => [ |
|
| 52 | - 'key' => 'value', |
|
| 53 | - ], |
|
| 54 | - 'string' => [ |
|
| 55 | - 'key' => 'value', |
|
| 56 | - ], |
|
| 57 | - ], |
|
| 39 | + 'converter' => [ |
|
| 40 | + 'primitives' => [ |
|
| 41 | + /* Configuration for primitives used when such data is passed directly as payload (i.e. `success(15)`;) */ |
|
| 42 | + 'array' => [ |
|
| 43 | + 'key' => 'values', |
|
| 44 | + ], |
|
| 45 | + 'boolean' => [ |
|
| 46 | + 'key' => 'value', |
|
| 47 | + ], |
|
| 48 | + 'double' => [ |
|
| 49 | + 'key' => 'value', |
|
| 50 | + ], |
|
| 51 | + 'integer' => [ |
|
| 52 | + 'key' => 'value', |
|
| 53 | + ], |
|
| 54 | + 'string' => [ |
|
| 55 | + 'key' => 'value', |
|
| 56 | + ], |
|
| 57 | + ], |
|
| 58 | 58 | |
| 59 | - /* Object converters configuration for supported classes */ |
|
| 60 | - 'classes' => [ |
|
| 61 | - \Illuminate\Database\Eloquent\Model::class => [ |
|
| 62 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 63 | - 'key' => 'item', |
|
| 64 | - 'pri' => 0, |
|
| 65 | - ], |
|
| 66 | - \Illuminate\Support\Collection::class => [ |
|
| 67 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 68 | - 'key' => 'items', |
|
| 69 | - 'pri' => 0, |
|
| 70 | - ], |
|
| 71 | - \Illuminate\Database\Eloquent\Collection::class => [ |
|
| 72 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 73 | - 'key' => 'items', |
|
| 74 | - 'pri' => 0, |
|
| 75 | - ], |
|
| 76 | - \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
| 77 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 78 | - 'key' => 'item', |
|
| 79 | - 'pri' => 0, |
|
| 80 | - ], |
|
| 59 | + /* Object converters configuration for supported classes */ |
|
| 60 | + 'classes' => [ |
|
| 61 | + \Illuminate\Database\Eloquent\Model::class => [ |
|
| 62 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 63 | + 'key' => 'item', |
|
| 64 | + 'pri' => 0, |
|
| 65 | + ], |
|
| 66 | + \Illuminate\Support\Collection::class => [ |
|
| 67 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 68 | + 'key' => 'items', |
|
| 69 | + 'pri' => 0, |
|
| 70 | + ], |
|
| 71 | + \Illuminate\Database\Eloquent\Collection::class => [ |
|
| 72 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 73 | + 'key' => 'items', |
|
| 74 | + 'pri' => 0, |
|
| 75 | + ], |
|
| 76 | + \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
| 77 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ToArrayConverter::class, |
|
| 78 | + 'key' => 'item', |
|
| 79 | + 'pri' => 0, |
|
| 80 | + ], |
|
| 81 | 81 | |
| 82 | - /* |
|
| 82 | + /* |
|
| 83 | 83 | |----------------------------------------------------------------------------------------------------------- |
| 84 | 84 | | Generic converters should have lower pri to allow dedicated ones to kick in first when class matches |
| 85 | 85 | |----------------------------------------------------------------------------------------------------------- |
| 86 | 86 | */ |
| 87 | - \JsonSerializable::class => [ |
|
| 88 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\JsonSerializableConverter::class, |
|
| 89 | - 'key' => 'item', |
|
| 90 | - 'pri' => -10, |
|
| 91 | - ], |
|
| 92 | - \Illuminate\Contracts\Support\Arrayable::class => [ |
|
| 93 | - 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
| 94 | - 'key' => 'items', |
|
| 95 | - 'pri' => -10, |
|
| 96 | - ], |
|
| 97 | - ], |
|
| 87 | + \JsonSerializable::class => [ |
|
| 88 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\JsonSerializableConverter::class, |
|
| 89 | + 'key' => 'item', |
|
| 90 | + 'pri' => -10, |
|
| 91 | + ], |
|
| 92 | + \Illuminate\Contracts\Support\Arrayable::class => [ |
|
| 93 | + 'handler' => \MarcinOrlowski\ResponseBuilder\Converters\ArrayableConverter::class, |
|
| 94 | + 'key' => 'items', |
|
| 95 | + 'pri' => -10, |
|
| 96 | + ], |
|
| 97 | + ], |
|
| 98 | 98 | |
| 99 | - ], |
|
| 99 | + ], |
|
| 100 | 100 | |
| 101 | - /* |
|
| 101 | + /* |
|
| 102 | 102 | |----------------------------------------------------------------------------------------------------------- |
| 103 | 103 | | Exception handler error codes |
| 104 | 104 | |----------------------------------------------------------------------------------------------------------- |
| 105 | 105 | | |
| 106 | 106 | */ |
| 107 | - 'exception_handler' => [ |
|
| 108 | - /* |
|
| 107 | + 'exception_handler' => [ |
|
| 108 | + /* |
|
| 109 | 109 | * The following keys are supported for each handler specified. |
| 110 | 110 | * `handler` |
| 111 | 111 | * `pri` |
@@ -125,19 +125,19 @@ discard block |
||
| 125 | 125 | * message ($ex->getMessage()). |
| 126 | 126 | */ |
| 127 | 127 | |
| 128 | - \Illuminate\Validation\ValidationException::class => [ |
|
| 129 | - 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\ValidationExceptionHandler::class, |
|
| 130 | - 'pri' => -100, |
|
| 131 | - 'config' => [ |
|
| 128 | + \Illuminate\Validation\ValidationException::class => [ |
|
| 129 | + 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\ValidationExceptionHandler::class, |
|
| 130 | + 'pri' => -100, |
|
| 131 | + 'config' => [ |
|
| 132 | 132 | // 'api_code' => ApiCodes::YOUR_API_CODE_FOR_VALIDATION_EXCEPTION, |
| 133 | 133 | // 'http_code' => HttpResponse::HTTP_UNPROCESSABLE_ENTITY, |
| 134 | - ], |
|
| 135 | - ], |
|
| 134 | + ], |
|
| 135 | + ], |
|
| 136 | 136 | |
| 137 | 137 | \Symfony\Component\HttpKernel\Exception\HttpException::class => [ |
| 138 | - 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
| 139 | - 'pri' => -100, |
|
| 140 | - 'config' => [ |
|
| 138 | + 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
| 139 | + 'pri' => -100, |
|
| 140 | + 'config' => [ |
|
| 141 | 141 | // HttpException::class => [ |
| 142 | 142 | // // used by unauthenticated() to obtain api and http code for the exception |
| 143 | 143 | // HttpResponse::HTTP_UNAUTHORIZED => [ |
@@ -153,47 +153,47 @@ discard block |
||
| 153 | 153 | // 'http_code' => HttpResponse::HTTP_BAD_REQUEST, |
| 154 | 154 | // ], |
| 155 | 155 | // ], |
| 156 | - ], |
|
| 156 | + ], |
|
| 157 | 157 | // // This is final exception handler. If ex is not dealt with yet this is its last stop. |
| 158 | - // default handler is mandatory and MUST have both `api_code` and `http_code` set. |
|
| 158 | + // default handler is mandatory and MUST have both `api_code` and `http_code` set. |
|
| 159 | 159 | |
| 160 | - 'default' => [ |
|
| 161 | - 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
| 162 | - 'pri' => -127, |
|
| 163 | - 'config' => [ |
|
| 160 | + 'default' => [ |
|
| 161 | + 'handler' => \MarcinOrlowski\ResponseBuilder\ExceptionHandlers\HttpExceptionHandler::class, |
|
| 162 | + 'pri' => -127, |
|
| 163 | + 'config' => [ |
|
| 164 | 164 | // 'api_code' => ApiCodes::YOUR_API_CODE_FOR_UNHANDLED_EXCEPTION, |
| 165 | 165 | // 'http_code' => HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
| 166 | - ], |
|
| 167 | - ], |
|
| 168 | - ], |
|
| 169 | - ], |
|
| 166 | + ], |
|
| 167 | + ], |
|
| 168 | + ], |
|
| 169 | + ], |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |----------------------------------------------------------------------------------------------------------- |
| 173 | 173 | | data-to-json encoding options |
| 174 | 174 | |----------------------------------------------------------------------------------------------------------- |
| 175 | 175 | | |
| 176 | 176 | */ |
| 177 | - 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
| 177 | + 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
| 178 | 178 | |
| 179 | - /* |
|
| 179 | + /* |
|
| 180 | 180 | |----------------------------------------------------------------------------------------------------------- |
| 181 | 181 | | Debug config |
| 182 | 182 | |----------------------------------------------------------------------------------------------------------- |
| 183 | 183 | | |
| 184 | 184 | */ |
| 185 | - 'debug' => [ |
|
| 186 | - 'debug_key' => 'debug', |
|
| 187 | - 'exception_handler' => [ |
|
| 188 | - 'trace_key' => 'trace', |
|
| 189 | - 'trace_enabled' => env('APP_DEBUG', false), |
|
| 190 | - ], |
|
| 185 | + 'debug' => [ |
|
| 186 | + 'debug_key' => 'debug', |
|
| 187 | + 'exception_handler' => [ |
|
| 188 | + 'trace_key' => 'trace', |
|
| 189 | + 'trace_enabled' => env('APP_DEBUG', false), |
|
| 190 | + ], |
|
| 191 | 191 | |
| 192 | - // Controls debugging features of payload converter class. |
|
| 193 | - 'converter' => [ |
|
| 194 | - // Set to true to figure out what converter is used for given data payload and why. |
|
| 195 | - 'debug_enabled' => env('RB_CONVERTER_DEBUG', false), |
|
| 196 | - ], |
|
| 197 | - ], |
|
| 192 | + // Controls debugging features of payload converter class. |
|
| 193 | + 'converter' => [ |
|
| 194 | + // Set to true to figure out what converter is used for given data payload and why. |
|
| 195 | + 'debug_enabled' => env('RB_CONVERTER_DEBUG', false), |
|
| 196 | + ], |
|
| 197 | + ], |
|
| 198 | 198 | |
| 199 | 199 | ]; |
@@ -42,12 +42,12 @@ |
||
| 42 | 42 | $config = \array_replace($default_config, $user_config); |
| 43 | 43 | |
| 44 | 44 | $http_code = $ex->getStatusCode(); |
| 45 | - $result = $config[ $http_code ] ?? null; |
|
| 45 | + $result = $config[$http_code] ?? null; |
|
| 46 | 46 | |
| 47 | 47 | // If we do not have dedicated entry fort this particular http_code, |
| 48 | 48 | // fall back to default value. |
| 49 | 49 | if ($result === null) { |
| 50 | - $result = $config[ RB::KEY_DEFAULT ]; |
|
| 50 | + $result = $config[RB::KEY_DEFAULT]; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Some defaults to fall back to if not set in user config. |