1
0
Fork 0
mirror of synced 2024-06-17 10:14:50 +12:00

feat: add test for error message

This commit is contained in:
Christy Jacob 2022-02-13 13:12:16 +04:00
parent 9af621c8c2
commit 5fee7378ad
4 changed files with 23 additions and 5 deletions

View file

@ -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.',

View file

@ -375,14 +375,25 @@ 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;

View file

@ -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';

View file

@ -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']);
}