From f61740308c1ca672c89807eb9683366ab4942532 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 4 Jun 2016 18:14:17 +0200 Subject: [PATCH] Implement HTTP422 Unprocessable entity It's propably the most popular one, so why not implement it? --- src/AbstractResponse.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/AbstractResponse.php b/src/AbstractResponse.php index 4c38079..6d439b3 100644 --- a/src/AbstractResponse.php +++ b/src/AbstractResponse.php @@ -36,6 +36,9 @@ abstract class AbstractResponse implements Response const CODE_METHOD_NOT_ALLOWED = 'GEN-METHOD-NOT-ALLOWED'; const CODE_UNWILLING_TO_PROCESS = 'GEN-UNWILLING-TO-PROCESS'; + + const CODE_UNPROCESSABLE = 'GEN-UNPROCESSABLE'; + /** * HTTP Status code @@ -265,4 +268,16 @@ public function errorUnwillingToProcess($message = 'Server is unwilling to proce { return $this->setStatusCode(431)->withError($message, static::CODE_UNWILLING_TO_PROCESS, $headers); } -} \ No newline at end of file + + /** + * Generates a Response with a 422 HTTP header and a given message. + * + * @param string $message + * @param array $headers + * @return mixed + */ + public function errorUnprocessable($message = 'Unprocessable Entity', array $headers = []) + { + return $this->setStatusCode(422)->withError($message, static::CODE_UNPROCESSABLE, $headers); + } +}