diff options
author | Chaoyi Zha <summermontreal@gmail.com> | 2017-03-21 00:19:28 +0300 |
---|---|---|
committer | Chaoyi Zha <summermontreal@gmail.com> | 2017-03-21 00:19:28 +0300 |
commit | fc056a9364b6bcb0116d4407d002f75a768e3152 (patch) | |
tree | 9ef977e9bc86cc6af59d9273210895a2307590ec | |
parent | e786fc2cc1054bea7eca0b58e2c47dc3bbdd5b54 (diff) |
Ignore empty , throw ApiException for all AUTH_ERROR instances
-rw-r--r-- | app/Factories/LinkFactory.php | 4 | ||||
-rw-r--r-- | app/Http/Middleware/ApiMiddleware.php | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/app/Factories/LinkFactory.php b/app/Factories/LinkFactory.php index 21a3bc7..2320613 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 && (!isset($custom_ending)) && (LinkHelper::longLinkExists($long_url) !== false)) { + if (!$is_secret && (!isset($custom_ending) || $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 (isset($custom_ending)) { + if (isset($custom_ending) && $custom_ending !== '') { // has custom ending $ending_conforms = LinkHelper::validateEnding($custom_ending); if (!$ending_conforms) { diff --git a/app/Http/Middleware/ApiMiddleware.php b/app/Http/Middleware/ApiMiddleware.php index 6c4e5eb..bbab80c 100644 --- a/app/Http/Middleware/ApiMiddleware.php +++ b/app/Http/Middleware/ApiMiddleware.php @@ -33,7 +33,7 @@ class ApiMiddleware { ->first(); if (!$user) { - abort(401, "Invalid authentication token."); + throw new ApiException('AUTH_ERROR', 'Authentication token required.', 401, $response_type); } $username = $user->username; } |