diff options
Diffstat (limited to 'src/CamilStaps')
-rw-r--r-- | src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php | 11 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Exception/ValidationException.php | 18 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php index 4d6c93c..6351614 100644 --- a/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php +++ b/src/CamilStaps/BotleaguesApi/BotleaguesApiServiceProvider.php @@ -1,7 +1,6 @@ <?php namespace CamilStaps\BotleaguesApi; -use \Illuminate\Database\Eloquent\ModelNotFoundException; use \Illuminate\Support\ServiceProvider; use \Illuminate\Support\Facades\App; use \Illuminate\Support\Facades\Config; @@ -37,7 +36,7 @@ class BotleaguesApiServiceProvider extends ServiceProvider { 500); }); - API::error(function(ModelNotFoundException $e) { + API::error(function(\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return Response::make( ['error' => 'Resource not found'], 404); @@ -47,6 +46,14 @@ class BotleaguesApiServiceProvider extends ServiceProvider { ['error' => !Config::get('app.debug') || empty($e->getMessage()) ? 'Access denied' : $e->getMessage()], 404); }); + API::error(function(Exception\ValidationException $e) { + return Response::make( + [ + 'error' => $e->getMessage(), + 'errors' => $e->errors + ], + 500); + }); API::error(function(\Exception $e) { return Response::make( ['error' => Config::get('app.debug') ? $e->getMessage() : "Internal error"], diff --git a/src/CamilStaps/BotleaguesApi/Exception/ValidationException.php b/src/CamilStaps/BotleaguesApi/Exception/ValidationException.php new file mode 100644 index 0000000..c59ae6f --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Exception/ValidationException.php @@ -0,0 +1,18 @@ +<?php +namespace CamilStaps\BotleaguesApi\Exception; + +use Symfony\Component\HttpKernel\Exception\HttpException; + +class ValidationException extends HttpException { + + public function __construct($message = null, $errors = null, Exception $previous = null, $headers = [], $code = 0) { + if (is_null($errors)) { + $this->errors = new MessageBag; + } else { + $this->errors = is_array($errors) ? new MessageBag($errors) : $errors; + } + + parent::__construct(422, $message, $previous, $headers, $code); + } + +}
\ No newline at end of file |