Skip to content

Do not report validation errors as rate limits - #87

Merged
cursedcoder merged 1 commit into
KnpLabs:masterfrom
kasperg:patch-1
Nov 15, 2013
Merged

cursedcoder merged 1 commit into
KnpLabs:masterfrom
kasperg:patch-1

Conversation

@kasperg

@kasperg kasperg commented Nov 15, 2013

Copy link
Copy Markdown
Contributor

When receiving a validation error (as in #86) there is no X-RateLimit-Remaining header included with the response. That is quite confusing.

Here $remaining when cast to a string is set to "" (empty string). This does not strictly equal null and thus a ApiLimitExceedException is thrown.

This change fixes this behavior.

cURL requests/responses:

# Request:
POST /repos/kasperg/release-asset-test/releases/92217/assets?name=test2.txt HTTP/1.1
Host: uploads.github.com
0: Accept: application/vnd.github.v3+json
1: User-Agent: php-github-api (http://github.com/KnpLabs/php-github-api)
Content-Type: text/plain, text/plain
User-Agent: Guzzle/3.7.4 curl/7.30.0 PHP/5.3.27
Authorization: Basic SomePassword
Content-Length: 14

{"body":"122"}

# Response:
HTTP/1.1 422 status code 422
Cache-Control: no-cache
Content-Length: 214
Content-Type: application/json; charset=utf-8
X-Content-Type-Options: nosniff
X-Github-Media-Type: github.beta; format=json
X-Github-Request-Id: a6633df9-4dff-11e3-800a-0be28f962e12
Date: Fri, 15 Nov 2013 14:10:15 GMT

{"message":"Validation Failed","request_id":"a6633df9-4dff-11e3-800a-0be28f962e12","documentation_url":"http://developer.github.com/v3","errors":[{"resource":"ReleaseAsset","code":"already_exists","field":"name"}]}

When receiving a validation error (as in KnpLabs#86) there is no `X-RateLimit-Remaining` header included with the response. That is quite confusing.

Here `$remaining` when cast to a string is set to "" (empty string). This does not strictly equal null and thus a `ApiLimitExceedException` is thrown.

This change fixes this behavior.

cURL requests/responses:

```
# Request:
POST /repos/kasperg/release-asset-test/releases/92217/assets?name=test2.txt HTTP/1.1
Host: uploads.github.com
0: Accept: application/vnd.github.v3+json
1: User-Agent: php-github-api (http://github.com/KnpLabs/php-github-api)
Content-Type: text/plain, text/plain
User-Agent: Guzzle/3.7.4 curl/7.30.0 PHP/5.3.27
Authorization: Basic a2FzcGVyZzpwaW5rbW9ucw==
Content-Length: 14

{"body":"122"}

# Response:
HTTP/1.1 422 status code 422
Cache-Control: no-cache
Content-Length: 214
Content-Type: application/json; charset=utf-8
X-Content-Type-Options: nosniff
X-Github-Media-Type: github.beta; format=json
X-Github-Request-Id: a6633df9-4dff-11e3-800a-0be28f962e12
Date: Fri, 15 Nov 2013 14:10:15 GMT

{"message":"Validation Failed","request_id":"a6633df9-4dff-11e3-800a-0be28f962e12","documentation_url":"http://developer.github.com/v3","errors":[{"resource":"ReleaseAsset","code":"already_exists","field":"name"}]}
```
cursedcoder added a commit that referenced this pull request Nov 15, 2013
Do not report validation errors as rate limits
@cursedcoder
cursedcoder merged commit 92203a6 into KnpLabs:master Nov 15, 2013
@cursedcoder

Copy link
Copy Markdown
Contributor

Thanks! Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants