Add hasRedirect() method for OAuthServerException

Resolves #694.
This commit is contained in:
Ian Littman 2017-02-04 14:48:40 -05:00
parent ded7c1ed47
commit d8ece093d5
2 changed files with 30 additions and 0 deletions

View File

@ -273,6 +273,19 @@ class OAuthServerException extends \Exception
return $headers;
}
/**
* Returns whether the exception includes a redirect, since
* getHttpStatusCode() doesn't return a 302 when there's a
* redirect enabled. This helps when you want to override local
* error pages but want to let redirects through.
*
* @return bool
*/
public function hasRedirect()
{
return $this->redirectUri !== null;
}
/**
* Returns the HTTP status code to send when the exceptions is output.
*

17
tests/ExceptionTest.php Normal file
View File

@ -0,0 +1,17 @@
<?php
namespace LeagueTests\Utils;
use League\OAuth2\Server\Exception\OAuthServerException;
class ExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testHasRedirect()
{
$exceptionWithoutRedirect = OAuthServerException::accessDenied('Some hint');
$this->assertFalse($exceptionWithoutRedirect->hasRedirect());
$exceptionWithRedirect = OAuthServerException::accessDenied('some hint', 'https://example.com/error');
$this->assertTrue($exceptionWithRedirect->hasRedirect());
}
}