Skip to content

Commit

Permalink
Support streaming API error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlinc committed Feb 16, 2016
1 parent 6389a5b commit 3abe582
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Webservice/TwitterWebservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,20 @@ protected function _doRequest($url, $parameters)

protected function _checkResponse(Response $response)
{
if (isset($response->json['errors'][0]['message'])) {
$error = $response->json['errors'][0]['message'];
} else {
$error = $response->body();
}
switch ($response->statusCode()) {
case 404:
throw new NotFoundException($response->json['errors'][0]['message']);
throw new NotFoundException($error);
case 429:
throw new RateLimitExceededException($response->json['errors'][0]['message'], 429);
throw new RateLimitExceededException($error, 429);
}

if (!$response->isOk()) {
throw new UnknownErrorException([$response->statusCode(), $response->json['errors'][0]['message']]);
throw new UnknownErrorException([$response->statusCode(), $error]);
}
}

Expand Down

0 comments on commit 3abe582

Please sign in to comment.