* Parse a Vaas error response * @param Response $response The response to parse * @return Exception The exception to throw * @throws VaasAuthenticationException If the server did not accept the token from the identity provider * @throws VaasClientException If the error was caused by the client * @throws VaasServerException If the error was caused by the server */
(Response $response)
| 390 | * @throws VaasServerException If the error was caused by the server |
| 391 | */ |
| 392 | private function parseVaasError(Response $response): Exception |
| 393 | { |
| 394 | try { |
| 395 | $responseBody = $response->getBody()->buffer(); |
| 396 | $problemDetails = json_decode($responseBody, true); |
| 397 | if (json_last_error() === JSON_ERROR_NONE) { |
| 398 | throw match ($problemDetails['type'] ?? '') { |
| 399 | 'VaasClientException' => new VaasClientException($problemDetails['detail'] ?? 'Unknown client error'), |
| 400 | default => new VaasServerException($problemDetails['detail'] ?? 'Unknown server error'), |
| 401 | }; |
| 402 | } else { |
| 403 | throw new VaasServerException('Invalid JSON error response from VaaS backend'); |
| 404 | } |
| 405 | } catch (Exception) { |
| 406 | if ($response->getStatus() == 401) { |
| 407 | throw new VaasAuthenticationException( |
| 408 | 'Server did not accept token from identity provider. Check if you are using the correct identity provider and credentials.' |
| 409 | ); |
| 410 | } elseif ($response->isClientError()) { |
| 411 | throw new VaasClientException('HTTP Error: ' . $response->getStatus() . ' ' . $response->getReason()); |
| 412 | } |
| 413 | throw new VaasServerException('HTTP Error: ' . $response->getStatus() . ' ' . $response->getReason()); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | private static function logUri(Request $request): string |
| 418 | { |
no test coverage detected