Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cydrobolt/polr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaoyi Zha <summermontreal@gmail.com>2017-03-21 00:01:33 +0300
committerChaoyi Zha <summermontreal@gmail.com>2017-03-21 00:01:33 +0300
commitb643906752040b337eff1a91cf0fb7d4ba049e4a (patch)
treec982ea8bf0c6d360ee37feabd7e8116faac34b83
parent861665f4d778b4d4d675d48ead523f7e769551c9 (diff)
Fix custom ending bug affecting non-truthy endings, update documentation for API error updates
-rw-r--r--app/Factories/LinkFactory.php4
-rw-r--r--app/Http/Controllers/Api/ApiLinkController.php2
-rw-r--r--docs/developer-guide/api.md6
-rw-r--r--docs/developer-guide/api_errors.md19
-rw-r--r--mkdocs.yml1
5 files changed, 27 insertions, 5 deletions
diff --git a/app/Factories/LinkFactory.php b/app/Factories/LinkFactory.php
index 0e468e2..21a3bc7 100644
--- a/app/Factories/LinkFactory.php
+++ b/app/Factories/LinkFactory.php
@@ -55,14 +55,14 @@ class LinkFactory {
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) {
diff --git a/app/Http/Controllers/Api/ApiLinkController.php b/app/Http/Controllers/Api/ApiLinkController.php
index 063ce6e..b41202c 100644
--- a/app/Http/Controllers/Api/ApiLinkController.php
+++ b/app/Http/Controllers/Api/ApiLinkController.php
@@ -33,7 +33,7 @@ class ApiLinkController extends ApiController {
$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);
diff --git a/docs/developer-guide/api.md b/docs/developer-guide/api.md
index c7f854b..b0edd90 100644
--- a/docs/developer-guide/api.md
+++ b/docs/developer-guide/api.md
@@ -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
diff --git a/docs/developer-guide/api_errors.md b/docs/developer-guide/api_errors.md
new file mode 100644
index 0000000..62f5585
--- /dev/null
+++ b/docs/developer-guide/api_errors.md
@@ -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.
diff --git a/mkdocs.yml b/mkdocs.yml
index 81f9b7a..53198a1 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -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'