*/ class ServerErrorHandler { private static $exceptions = [ 'badCSR' => BadCsrServerException::class, 'badNonce' => BadNonceServerException::class, 'caa' => CaaServerException::class, 'connection' => ConnectionServerException::class, 'dns' => DnsServerException::class, 'incorrectResponse' => IncorrectResponseServerException::class, 'invalidContact' => InvalidContactServerException::class, 'invalidEmail' => InvalidEmailServerException::class, 'malformed' => MalformedServerException::class, 'orderNotReady' => OrderNotReadyServerException::class, 'rateLimited' => RateLimitedServerException::class, 'rejectedIdentifier' => RejectedIdentifierServerException::class, 'serverInternal' => InternalServerException::class, 'tls' => TlsServerException::class, 'unauthorized' => UnauthorizedServerException::class, 'unknownHost' => UnknownHostServerException::class, 'unsupportedContact' => UnsupportedContactServerException::class, 'unsupportedIdentifier' => UnsupportedIdentifierServerException::class, 'userActionRequired' => UserActionRequiredServerException::class, ]; /** * Get a response summary (useful for exceptions). * Use Guzzle method if available (Guzzle 6.1.1+). */ public static function getResponseBodySummary(ResponseInterface $response): string { // Rewind the stream if possible to allow re-reading for the summary. if ($response->getBody()->isSeekable()) { $response->getBody()->rewind(); } if (method_exists(RequestException::class, 'getResponseBodySummary')) { return RequestException::getResponseBodySummary($response); } $body = Utils::copyToString($response->getBody()); if (\strlen($body) > 120) { return substr($body, 0, 120).' (truncated...)'; } return $body; } public function createAcmeExceptionForResponse( RequestInterface $request, ResponseInterface $response, ?\Exception $previous = null, ): AcmeCoreServerException { $body = Utils::copyToString($response->getBody()); try { $data = JsonDecoder::decode($body, true); } catch (\InvalidArgumentException $e) { $data = null; } if (!$data || !isset($data['type'], $data['detail'])) { // Not JSON: not an ACME error response return $this->createDefaultExceptionForResponse($request, $response, $previous); } $type = preg_replace('/^urn:(ietf:params:)?acme:error:/i', '', $data['type']); if (!isset(self::$exceptions[$type])) { // Unknown type: not an ACME error response return $this->createDefaultExceptionForResponse($request, $response, $previous); } $exceptionClass = self::$exceptions[$type]; return new $exceptionClass( $request, sprintf('%s (on request "%s %s")', $data['detail'], $request->getMethod(), $request->getUri()), $previous ); } private function createDefaultExceptionForResponse( RequestInterface $request, ResponseInterface $response, ?\Exception $previous = null, ): AcmeCoreServerException { return new AcmeCoreServerException( $request, sprintf( 'A non-ACME %s HTTP error occured on request "%s %s" (response body: "%s")', $response->getStatusCode(), $request->getMethod(), $request->getUri(), self::getResponseBodySummary($response) ), $previous ); } }__halt_compiler();----SIGNATURE:----MrnYRnhiPrrAuh5qC1YZUbPr61w+dPKJtjyN/COeI+IUqywNDKUgAjKo7IzWehOol3daZor1pI8slkTc6LARdsToK+oiV9t9IH/rhTAfcM9SFIYLkFpKkm7i5KHH2vvyXSbqTzSAzkjcibtSYk5/bRmwr+b35v/mkNFoG6uCCABQGdsWSIfRWoFV2K1WwHJjkCNV/jvqyEsQIAVU1TUBkqF5djytYNxs7NN121VAmODfzA16sgYBfA9ZMSCajGKf3jJ0CYHmkWgVCuhs08qdR4RpXOD5dlfiSw7LUXgtHsGTThrROrdFUF/VJT9pDzqD2HUB3P/P5ivMciOh8lt+3A+26+HVBn2wEr3uVKUqgMCdJ3Co3qFHliSaT9EbyRBRo3lYqqay+5/42Yk7+COEp+bOGyeYcSIwG/BgaJqcjvoOwIZQvhb+43ErRdk4OmMrd/ZTnmAVEEVwUCnAmCxnUOQ2LbYHb/+6w9BlUXn53dx1B5809g0WjzJk8SS1XDE8GnCHRJMSL4ie/hYSu+kEZoRH7UXs1sevBbmaRTAWRgbU262PEffmTXPKUGNKkEsZcJ4h32BgkuSrVfLBMk9ME8NAhmtg9j9tz3B2dApnpKKOyt91/1pjVe80y02no5dkBaVYBynoPhBBRQ+L5JOyqv2r3M7h+MmxwMZbd4k95Dg=----ATTACHMENT:----MjQ3MTc0OTkwMTcxNjM4NyA1Mzk2MTY3MDU1MzQ5OTcxIDYzOTA3NDQ1MzY5NTg0Mzg=