ActionController: helper method for JSON errors
This commit is contained in:
parent
8b3d72a04a
commit
1329d01280
|
@ -166,6 +166,27 @@ abstract class ActionController extends Controller
|
|||
$this->prepareTable($name)->render('list/table', null, true);
|
||||
}
|
||||
|
||||
// TODO: just return json_last_error_msg() for PHP >= 5.5.0
|
||||
protected function getLastJsonError()
|
||||
{
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_DEPTH:
|
||||
return 'The maximum stack depth has been exceeded';
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
return 'Control character error, possibly incorrectly encoded';
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
return 'Invalid or malformed JSON';
|
||||
case JSON_ERROR_SYNTAX:
|
||||
return 'Syntax error';
|
||||
case JSON_ERROR_UTF8:
|
||||
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||
default:
|
||||
return 'An error occured when parsing a JSON string';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function api($endpointName = null)
|
||||
{
|
||||
if ($this->api === null) {
|
||||
|
|
Loading…
Reference in New Issue