Smooth error catching.

This commit is contained in:
James Cole 2017-09-29 15:32:47 +02:00
parent d306183c95
commit 40f2659b91
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -175,32 +175,24 @@ class CsvProcessor implements FileProcessorInterface
*/ */
private function getJsonError(int $jsonError): string private function getJsonError(int $jsonError): string
{ {
switch ($jsonError) { $messages = [
default: JSON_ERROR_NONE => 'No JSON error',
return 'Unknown JSON error'; JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
case JSON_ERROR_NONE: JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
return 'No JSON error'; JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
case JSON_ERROR_DEPTH: JSON_ERROR_SYNTAX => 'Syntax error.',
return 'JSON_ERROR_DEPTH'; JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
case JSON_ERROR_STATE_MISMATCH: JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
return 'JSON_ERROR_STATE_MISMATCH'; JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
case JSON_ERROR_CTRL_CHAR: JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
return 'JSON_ERROR_CTRL_CHAR'; JSON_ERROR_INVALID_PROPERTY_NAME => 'A property name that cannot be encoded was given.',
case JSON_ERROR_SYNTAX: JSON_ERROR_UTF16 => 'Malformed UTF-16 characters, possibly incorrectly encoded.',
return 'JSON_ERROR_SYNTAX'; ];
case JSON_ERROR_UTF8: if (isset($messages[$jsonError])) {
return 'JSON_ERROR_UTF8'; return $messages[$jsonError];
case JSON_ERROR_RECURSION:
return 'JSON_ERROR_RECURSION';
case JSON_ERROR_INF_OR_NAN:
return 'JSON_ERROR_INF_OR_NAN';
case JSON_ERROR_UNSUPPORTED_TYPE:
return 'JSON_ERROR_UNSUPPORTED_TYPE';
case JSON_ERROR_INVALID_PROPERTY_NAME:
return 'JSON_ERROR_INVALID_PROPERTY_NAME';
case JSON_ERROR_UTF16:
return 'JSON_ERROR_UTF16';
} }
return 'Unknown JSON error';
} }
/** /**