Skip to content

Commit

Permalink
Fix custom ending bug affecting non-truthy endings, update documentat…
Browse files Browse the repository at this point in the history
…ion for API error updates
  • Loading branch information
cydrobolt committed Mar 20, 2017
1 parent 861665f commit b643906
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/Factories/LinkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public static function createLink($long_url, $is_secret=false, $custom_ending=nu
looks like a shortened URL.');
}

if (!$is_secret && !$custom_ending && (LinkHelper::longLinkExists($long_url) !== false)) {
if (!$is_secret && (!isset($custom_ending)) && (LinkHelper::longLinkExists($long_url) !== false)) {
// if link is not specified as secret, is non-custom, and
// already exists in Polr, lookup the value and return
$existing_link = LinkHelper::longLinkExists($long_url);
return self::formatLink($existing_link);
}

if ($custom_ending) {
if (isset($custom_ending)) {
// has custom ending
$ending_conforms = LinkHelper::validateEnding($custom_ending);
if (!$ending_conforms) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/ApiLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function shortenLink(Request $request) {
$formatted_link = LinkFactory::createLink($long_url, $is_secret, $custom_ending, $link_ip, $user->username, false, true);
}
catch (\Exception $e) {
throw new ApiException('CREATE_ERROR', $e->getMessage(), 400, $response_type);
throw new ApiException('CREATION_ERROR', $e->getMessage(), 400, $response_type);
}

return self::encodeResponse($formatted_link, 'shorten', $response_type);
Expand Down
6 changes: 4 additions & 2 deletions docs/developer-guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,15 @@ This status code is returned in the following circumstances:
Example `json` error response:
```
{
"error": "custom ending already in use"
"status_code":429,
"error_code":"QUOTA_EXCEEDED",
"error":"Quota exceeded."
}
```

Example `plain_text` error response:

`custom ending already in use`
`429 Quota exceeded.`

## Testing the API

Expand Down
19 changes: 19 additions & 0 deletions docs/developer-guide/api_errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## API Error Text Codes

`SERVER_ERROR`: A generic, unhandled error has occured.

`JSON_ONLY`: Only JSON-encoded data is available for this endpoint.

`MISSING_PARAMETERS`: Invalid or missing parameters.

`NOT_FOUND`: Object not found.

`ACCESS_DENIED`: User is not authorized to access the object.

`INVALID_ANALYTICS_TYPE`: Invalid analytics type requested.

`CREATION_ERROR`: An error occurred while creating the object.

`AUTH_ERROR`: An error occured while attempting to authenticate the user to the API.

`QUOTA_EXCEEDED`: User's API usage has exceeded alloted quota.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pages:
- Developer Guide:
- 'Libraries': 'developer-guide/libraries.md'
- 'API Documentation': 'developer-guide/api.md'
- 'API Errors': 'developer-guide/api_errors.md'
- About:
- 'License': 'about/license.md'
- 'Contributors': 'about/contributors.md'
Expand Down

0 comments on commit b643906

Please sign in to comment.