feat: add test for error message
This commit is contained in:
parent
9af621c8c2
commit
5fee7378ad
|
@ -58,6 +58,11 @@ return [
|
|||
'description' => 'The query\'s syntax is invalid. Please check the query and try again.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::GENERAL_ROUTE_NOT_FOUND => [
|
||||
'name' => Exception::GENERAL_ROUTE_NOT_FOUND,
|
||||
'description' => 'The requested route was not found. Please refer to the docs and try again.',
|
||||
'code' => 404,
|
||||
],
|
||||
Exception::GENERAL_CURSOR_NOT_FOUND => [
|
||||
'name' => Exception::GENERAL_CURSOR_NOT_FOUND,
|
||||
'description' => 'The cursor is invalid. This can happen if the item represented by the cursor has been deleted.',
|
||||
|
|
|
@ -375,15 +375,26 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project, $l
|
|||
throw $error;
|
||||
}
|
||||
|
||||
|
||||
/** Handle Utopia Errors */
|
||||
if ($error instanceof Utopia\Exception) {
|
||||
$code = $error->getCode();
|
||||
$error = new Exception($error->getMessage(), $code, Exception::GENERAL_UNKNOWN, $error);
|
||||
switch($code) {
|
||||
case 400:
|
||||
$error->setType(Exception::GENERAL_ARGUMENT_INVALID);
|
||||
break;
|
||||
case 404:
|
||||
$error->setType(Exception::GENERAL_ROUTE_NOT_FOUND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Wrap all exceptions inside Appwrite\Extend\Exception */
|
||||
if (!($error instanceof Exception)) {
|
||||
$error = new Exception($error->getMessage(), $error->getCode(), Exception::GENERAL_UNKNOWN, $error);
|
||||
}
|
||||
|
||||
if ($error instanceof Utopia\Exception && $error->getCode() === 400) {
|
||||
$error->setType(Exception::GENERAL_ARGUMENT_INVALID);
|
||||
}
|
||||
|
||||
$template = ($route) ? $route->getLabel('error', null) : null;
|
||||
|
||||
if (php_sapi_name() === 'cli') {
|
||||
|
|
|
@ -42,6 +42,7 @@ class Exception extends \Exception
|
|||
const GENERAL_ARGUMENT_INVALID = 'general_argument_invalid';
|
||||
const GENERAL_QUERY_LIMIT_EXCEEDED = 'general_query_limit_exceeded';
|
||||
const GENERAL_QUERY_INVALID = 'general_query_invalid';
|
||||
const GENERAL_ROUTE_NOT_FOUND = 'general_route_not_found';
|
||||
const GENERAL_CURSOR_NOT_FOUND = 'general_cursor_not_found';
|
||||
const GENERAL_SERVER_ERROR = 'general_server_error';
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Tests\E2E\General;
|
||||
|
||||
use Exception;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectNone;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
|
@ -45,6 +45,7 @@ class HTTPTest extends Scope
|
|||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
$this->assertEquals('Not Found', $response['body']['message']);
|
||||
$this->assertEquals(Exception::GENERAL_ROUTE_NOT_FOUND, $response['body']['type']);
|
||||
$this->assertEquals(404, $response['body']['code']);
|
||||
$this->assertEquals('dev', $response['body']['version']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue