Skip to content

Commit

Permalink
Implement HTTP422 Unprocessable entity
Browse files Browse the repository at this point in the history
It's propably the most popular one, so why not implement it?
  • Loading branch information
gholol committed Jun 4, 2016
1 parent bf10e85 commit f617403
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

/**
* 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);
}
}

0 comments on commit f617403

Please sign in to comment.