Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: fallback to guessing error type from HTTP status code in HEAD requests #673

Open
wants to merge 5 commits into
base: v3-v2021-02-25
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/recurly/recurly_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ public static function fromResponse(\Recurly\Response $response): \Recurly\Recur
$api_error = \Recurly\Resources\ErrorMayHaveTransaction::fromResponse($response, $error);
return new $klass($error->message, $api_error);
}
} else {
$error_type = static::errorFromStatus($response->getStatusCode());
$klass = static::titleize($error_type, '\\Recurly\\Errors\\');
if (class_exists($klass)) {
return new $klass('An unexpected error has occurred');
}
}

// "Content-type: application/json" may appear without a body after a HEAD request.
// If the above failed, try guessing from the status code.
$error_type = static::errorFromStatus($response->getStatusCode());
$klass = static::titleize($error_type, '\\Recurly\\Errors\\');
if (class_exists($klass)) {
return new $klass('An unexpected error has occurred');
}

// No valid error type was found, sorry.
$klass = static::_defaultErrorType($response);
return new $klass('An unexpected error has occurred');

Expand Down