-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create detector for detect errors in response
- Loading branch information
1 parent
e4384ad
commit a585948
Showing
11 changed files
with
259 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <[email protected]> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception; | ||
|
||
class BannedException extends ErrorException | ||
{ | ||
/** | ||
* @return BannedException | ||
*/ | ||
public static function banned() | ||
{ | ||
return new self('Access has been restricted for this account.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <[email protected]> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception; | ||
|
||
class ErrorException extends \RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <[email protected]> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception; | ||
|
||
class NotFoundException extends ErrorException | ||
{ | ||
/** | ||
* @return NotFoundException | ||
*/ | ||
public static function page() | ||
{ | ||
return new self('Page not found.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* AnimeDb package. | ||
* | ||
* @author Peter Gribanov <[email protected]> | ||
* @copyright Copyright (c) 2011, Peter Gribanov | ||
* @license http://opensource.org/licenses/GPL-3.0 GPL v3 | ||
*/ | ||
|
||
namespace AnimeDb\Bundle\MyAnimeListBrowserBundle\Service; | ||
|
||
use AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception\BannedException; | ||
use AnimeDb\Bundle\MyAnimeListBrowserBundle\Exception\NotFoundException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ErrorDetector | ||
{ | ||
/** | ||
* @param ResponseInterface $response | ||
* | ||
* @return string | ||
*/ | ||
public function detect(ResponseInterface $response) | ||
{ | ||
if ($response->getStatusCode() == 404) { | ||
throw NotFoundException::page(); | ||
} | ||
|
||
$content = $response->getBody()->getContents(); | ||
|
||
if (strpos($content, 'Access has been restricted for this account.') !== false) { | ||
throw BannedException::banned(); | ||
} | ||
|
||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.