wrapException($exception); } } protected function wrapException(RequestException $exception) { if ($exception->hasResponse()) { $exception->getResponse()->getBody()->seek(0); $contents = json_decode($exception->getResponse()->getBody()->getContents(), true); switch ($contents['error']) { case 'access_forbidden': return new AccessForbiddenException($contents, $exception); case 'resource_not_found': return new ResourceNotFoundException($contents, $exception); case 'token_invalid': return new TokenInvalidException($contents, $exception); case 'validation_failed': return new ValidationFailedException($contents, $exception); default: return new ShipXException($contents, $exception); } } return $exception; } }