Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method to throw errorUnprocessableEntity exception with status code 422. #1616

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Http/Response/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\Paginator;
use Dingo\Api\Transformer\Factory as TransformerFactory;
use Dingo\Api\Exception\ValidationHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;

class Factory
Expand Down Expand Up @@ -257,6 +258,20 @@ public function errorMethodNotAllowed($message = 'Method Not Allowed')
$this->error($message, 405);
}

/**
* Return a 422 unprocessable entity exception
*
* @param string $message
*
* @throws Dingo\Api\Exception\ValidationHttpException
*
* @return void
*/
public function errorUnprocessableEntity($message = "Unprocessable Entity")
{
throw new ValidationHttpException($message);
}

/**
* Call magic methods beginning with "with".
*
Expand All @@ -272,7 +287,7 @@ public function __call($method, $parameters)
if (Str::startsWith($method, 'with')) {
return call_user_func_array([$this, Str::camel(substr($method, 4))], $parameters);

// Because PHP won't let us name the method "array" we'll simply watch for it
// Because PHP won't let us name the method "array" we'll simply watch for it
// in here and return the new binding. Gross. This is now DEPRECATED and
// should not be used. Just return an array or a new response instance.
} elseif ($method == 'array') {
Expand Down