| Conditions | 6 |
| Paths | 7 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 4 | ||
| Bugs | 1 | Features | 2 |
| 1 | <?php |
||
| 33 | public function handle($request, Closure $next) |
||
| 34 | { |
||
| 35 | try { |
||
| 36 | $response = $next($request); |
||
| 37 | // Was an exception thrown? If so and available catch in our middleware |
||
| 38 | if (isset($response->exception) && $response->exception) { |
||
| 39 | throw $response->exception; |
||
| 40 | } |
||
| 41 | |||
| 42 | return $response; |
||
| 43 | } catch (OAuthException $e) { |
||
| 44 | $data = [ |
||
| 45 | 'error' => $e->errorType, |
||
| 46 | 'error_description' => $e->getMessage(), |
||
| 47 | ]; |
||
| 48 | |||
| 49 | $headers = []; |
||
| 50 | foreach ($e->getHttpHeaders() as $v) { |
||
| 51 | $parts = explode(':', $v); |
||
| 52 | if (count($parts) > 1) { |
||
| 53 | $headers[$parts[0]] = $parts[1]; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | return new JsonResponse($data, $e->httpStatusCode, $headers); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 |