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

Use native PHP Exception Code to transmit HTTP response code #54

Open
wants to merge 2 commits into
base: master
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
23 changes: 12 additions & 11 deletions Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,40 +298,41 @@ protected function checkLastResponseForError()

switch ($meta['http_code']) {
case 400:
throw new Pest_BadRequest($this->processError($body));
throw new Pest_BadRequest($this->processError($body), $meta['http_code']);
break;
case 401:
throw new Pest_Unauthorized($this->processError($body));
throw new Pest_Unauthorized($this->processError($body), $meta['http_code']);
break;
case 403:
throw new Pest_Forbidden($this->processError($body));
throw new Pest_Forbidden($this->processError($body), $meta['http_code']);
break;
case 404:
throw new Pest_NotFound($this->processError($body));
throw new Pest_NotFound($this->processError($body), $meta['http_code']);
break;
case 405:
throw new Pest_MethodNotAllowed($this->processError($body));
throw new Pest_MethodNotAllowed($this->processError($body), $meta['http_code']);
break;
case 409:
throw new Pest_Conflict($this->processError($body));
throw new Pest_Conflict($this->processError($body), $meta['http_code']);
break;
case 410:
throw new Pest_Gone($this->processError($body));
throw new Pest_Gone($this->processError($body), $meta['http_code']);
break;
case 422:
// Unprocessable Entity -- see http://www.iana.org/assignments/http-status-codes
// This is now commonly used (in Rails, at least) to indicate
// a response to a request that is syntactically correct,
// but semantically invalid (for example, when trying to
// create a resource with some required fields missing)
throw new Pest_InvalidRecord($this->processError($body));
throw new Pest_InvalidRecord($this->processError($body), $meta['http_code']);
break;
default:
if ($meta['http_code'] >= 400 && $meta['http_code'] <= 499)
throw new Pest_ClientError($this->processError($body));
throw new Pest_ClientError($this->processError($body), $meta['http_code']);
elseif ($meta['http_code'] >= 500 && $meta['http_code'] <= 599)
throw new Pest_ServerError($this->processError($body)); elseif (!isset($meta['http_code']) || $meta['http_code'] >= 600) {
throw new Pest_UnknownResponse($this->processError($body));
throw new Pest_ServerError($this->processError($body), $meta['http_code']);
elseif (!isset($meta['http_code']) || $meta['http_code'] >= 600) {
throw new Pest_UnknownResponse($this->processError($body), $meta['http_code']);
}
}
}
Expand Down