public function testPassesExceptionDetailsThroughAnAdaptor() { $request = 'x'; $e = new OAuthException('message here'); $e->errorType = 'invalid_client'; $e->httpStatusCode = 401; $mockAdaptor = m::mock(Adaptor::class)->shouldReceive('adapt')->with(['error' => 'invalid_client', 'error_description' => 'message here'], $e->httpStatusCode, $e->getHttpHeaders())->andReturn('this is a response')->getMock(); $mockAdaptorFactory = m::mock(AdaptorFactory::class)->shouldReceive('make')->with($request)->andReturn($mockAdaptor)->getMock(); $formatter = new LeagueOAuthExceptionFormatter($mockAdaptorFactory); $response = $formatter->handle($e, $request); $this->assertEquals('this is a response', $response); }
public function handle($request, \Closure $next) { try { $response = $next($request); // Laravel 5.2 doesn't throw exceptions, it returns responses with it included if (isset($response->exception) && $response->exception) { throw $response->exception; } return $response; } catch (OAuthException $e) { return $this->formatter->handle($e, $request); } }