| @@ 57-62 (lines=6) @@ | ||
| 54 | ||
| 55 | try { |
|
| 56 | $longUrl = $this->urlShortener->shortCodeToUrl($shortCode); |
|
| 57 | if ($longUrl === null) { |
|
| 58 | return new JsonResponse([ |
|
| 59 | 'error' => RestUtils::INVALID_ARGUMENT_ERROR, |
|
| 60 | 'message' => sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), |
|
| 61 | ], self::STATUS_NOT_FOUND); |
|
| 62 | } |
|
| 63 | ||
| 64 | return new JsonResponse([ |
|
| 65 | 'longUrl' => $longUrl, |
|
| @@ 87-94 (lines=8) @@ | ||
| 84 | // Get token making sure the an authorization type is provided |
|
| 85 | $authToken = $request->getHeaderLine(self::AUTHORIZATION_HEADER); |
|
| 86 | $authTokenParts = explode(' ', $authToken); |
|
| 87 | if (count($authTokenParts) === 1) { |
|
| 88 | return new JsonResponse([ |
|
| 89 | 'error' => RestUtils::INVALID_AUTHORIZATION_ERROR, |
|
| 90 | 'message' => sprintf($this->translator->translate( |
|
| 91 | 'You need to provide the Bearer type in the %s header.' |
|
| 92 | ), self::AUTHORIZATION_HEADER), |
|
| 93 | ], self::STATUS_UNAUTHORIZED); |
|
| 94 | } |
|
| 95 | ||
| 96 | // Make sure the authorization type is Bearer |
|
| 97 | list($authType, $jwt) = $authTokenParts; |
|
| @@ 98-105 (lines=8) @@ | ||
| 95 | ||
| 96 | // Make sure the authorization type is Bearer |
|
| 97 | list($authType, $jwt) = $authTokenParts; |
|
| 98 | if (strtolower($authType) !== 'bearer') { |
|
| 99 | return new JsonResponse([ |
|
| 100 | 'error' => RestUtils::INVALID_AUTHORIZATION_ERROR, |
|
| 101 | 'message' => sprintf($this->translator->translate( |
|
| 102 | 'Provided authorization type %s is not supported. Use Bearer instead.' |
|
| 103 | ), $authType), |
|
| 104 | ], self::STATUS_UNAUTHORIZED); |
|
| 105 | } |
|
| 106 | ||
| 107 | try { |
|
| 108 | ErrorHandler::start(); |
|