Switch over errors
This commit is contained in:
parent
550837b572
commit
a1d86c9b3f
1 changed files with 37 additions and 39 deletions
|
@ -853,6 +853,7 @@ App::error()
|
||||||
Console::info('Log pushed with status code: ' . $responseCode);
|
Console::info('Log pushed with status code: ' . $responseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$class = \get_class($error);
|
||||||
$code = $error->getCode();
|
$code = $error->getCode();
|
||||||
$message = $error->getMessage();
|
$message = $error->getMessage();
|
||||||
$file = $error->getFile();
|
$file = $error->getFile();
|
||||||
|
@ -873,8 +874,8 @@ App::error()
|
||||||
Console::error('[Error] Line: ' . $line);
|
Console::error('[Error] Line: ' . $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle Utopia Errors */
|
switch ($class) {
|
||||||
if ($error instanceof Utopia\Exception) {
|
case 'Utopia\Exception':
|
||||||
$error = new AppwriteException(AppwriteException::GENERAL_UNKNOWN, $message, $code, $error);
|
$error = new AppwriteException(AppwriteException::GENERAL_UNKNOWN, $message, $code, $error);
|
||||||
switch ($code) {
|
switch ($code) {
|
||||||
case 400:
|
case 400:
|
||||||
|
@ -884,35 +885,32 @@ App::error()
|
||||||
$error->setType(AppwriteException::GENERAL_ROUTE_NOT_FOUND);
|
$error->setType(AppwriteException::GENERAL_ROUTE_NOT_FOUND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Conflict) {
|
break;
|
||||||
|
case 'Utopia\Database\Exception\Conflict':
|
||||||
$error = new AppwriteException(AppwriteException::DOCUMENT_UPDATE_CONFLICT, previous: $error);
|
$error = new AppwriteException(AppwriteException::DOCUMENT_UPDATE_CONFLICT, previous: $error);
|
||||||
$code = $error->getCode();
|
break;
|
||||||
$message = $error->getMessage();
|
case 'Utopia\Database\Exception\Timeout':
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Timeout) {
|
|
||||||
$error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error);
|
$error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error);
|
||||||
$code = $error->getCode();
|
break;
|
||||||
$message = $error->getMessage();
|
case 'Utopia\Database\Exception\Query':
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Query) {
|
|
||||||
$error = new AppwriteException(AppwriteException::GENERAL_QUERY_INVALID, $error->getMessage(), previous: $error);
|
$error = new AppwriteException(AppwriteException::GENERAL_QUERY_INVALID, $error->getMessage(), previous: $error);
|
||||||
$code = $error->getCode();
|
break;
|
||||||
$message = $error->getMessage();
|
case 'Utopia\Database\Exception\Structure':
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Structure) {
|
|
||||||
$error = new AppwriteException(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $error->getMessage(), previous: $error);
|
$error = new AppwriteException(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $error->getMessage(), previous: $error);
|
||||||
$code = $error->getCode();
|
break;
|
||||||
$message = $error->getMessage();
|
case 'Utopia\Database\Exception\Duplicate':
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Duplicate) {
|
|
||||||
$error = new AppwriteException(AppwriteException::DOCUMENT_ALREADY_EXISTS);
|
$error = new AppwriteException(AppwriteException::DOCUMENT_ALREADY_EXISTS);
|
||||||
$code = $error->getCode();
|
break;
|
||||||
$message = $error->getMessage();
|
case 'Utopia\Database\Exception\Restricted':
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Restricted) {
|
|
||||||
$error = new AppwriteException(AppwriteException::DOCUMENT_DELETE_RESTRICTED);
|
$error = new AppwriteException(AppwriteException::DOCUMENT_DELETE_RESTRICTED);
|
||||||
$code = $error->getCode();
|
break;
|
||||||
$message = $error->getMessage();
|
case 'Utopia\Database\Exception\Authorization':
|
||||||
} elseif ($error instanceof Utopia\Database\Exception\Authorization) {
|
|
||||||
$error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED);
|
$error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$code = $error->getCode();
|
$code = $error->getCode();
|
||||||
$message = $error->getMessage();
|
$message = $error->getMessage();
|
||||||
}
|
|
||||||
|
|
||||||
/** Wrap all exceptions inside Appwrite\Extend\Exception */
|
/** Wrap all exceptions inside Appwrite\Extend\Exception */
|
||||||
if (!($error instanceof AppwriteException)) {
|
if (!($error instanceof AppwriteException)) {
|
||||||
|
|
Loading…
Reference in a new issue