From 3f994a30987dd7bf68254c54121031224574519e Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 19 Apr 2020 14:52:58 +0300 Subject: [PATCH] refactor(core): add api sys messages --- src/flextype/endpoints/delivery/entries.php | 30 +++-- src/flextype/endpoints/delivery/registry.php | 37 ++++-- src/flextype/endpoints/images/images.php | 22 ++-- src/flextype/endpoints/management/entries.php | 124 +++++++++++++----- 4 files changed, 151 insertions(+), 62 deletions(-) diff --git a/src/flextype/endpoints/delivery/entries.php b/src/flextype/endpoints/delivery/entries.php index 972101d5..a45ed43f 100644 --- a/src/flextype/endpoints/delivery/entries.php +++ b/src/flextype/endpoints/delivery/entries.php @@ -15,6 +15,12 @@ use Psr\Http\Message\ServerRequestInterface as Request; use function array_replace_recursive; use function count; +/** + * API sys messages + */ +$api_sys_messages['AccessTokenInvalid'] = ['sys' => ['type' => 'Error', 'id' => 'AccessTokenInvalid'], 'message' => 'The access token you sent could not be found or is invalid.']; +$api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound'], 'message' => 'The resource could not be found.']; + /** * Validate delivery entries token */ @@ -36,7 +42,7 @@ function validate_delivery_entries_token($token) : bool * Returns: * An array of entry item objects. */ -$app->get('/api/delivery/entries', function (Request $request, Response $response) use ($flextype) { +$app->get('/api/delivery/entries', function (Request $request, Response $response) use ($flextype, $api_sys_messages) { // Get Query Params $query = $request->getQueryParams(); @@ -56,35 +62,43 @@ $app->get('/api/delivery/entries', function (Request $request, Response $respons if ($delivery_entries_token_file_data = $flextype['parser']->decode(Filesystem::read($delivery_entries_token_file_path), 'yaml')) { if ($delivery_entries_token_file_data['state'] === 'disabled' || ($delivery_entries_token_file_data['limit_calls'] !== 0 && $delivery_entries_token_file_data['calls'] >= $delivery_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Fetch entry - $data['data'] = $flextype['entries']->fetch($id, $filter); + $response_data['data'] = $flextype['entries']->fetch($id, $filter); // Set response code - $response_code = count($data['data']) > 0 ? 200 : 404; + $response_code = count($response_data['data']) > 0 ? 200 : 404; // Update calls counter Filesystem::write($delivery_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_entries_token_file_data, ['calls' => $delivery_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response - ->withJson($data, $response_code) + ->withJson($response_data, $response_code) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); diff --git a/src/flextype/endpoints/delivery/registry.php b/src/flextype/endpoints/delivery/registry.php index 5826e773..5f1fa69e 100644 --- a/src/flextype/endpoints/delivery/registry.php +++ b/src/flextype/endpoints/delivery/registry.php @@ -14,6 +14,12 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use function array_replace_recursive; +/** + * API sys messages + */ +$api_sys_messages['AccessTokenInvalid'] = ['sys' => ['type' => 'Error', 'id' => 'AccessTokenInvalid'], 'message' => 'The access token you sent could not be found or is invalid.']; +$api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound'], 'message' => 'The resource could not be found.']; + /** * Validate delivery registry token */ @@ -34,7 +40,7 @@ function validate_delivery_registry_token($token) : bool * Returns: * An array of registry item objects. */ -$app->get('/api/delivery/registry', function (Request $request, Response $response) use ($flextype) { +$app->get('/api/delivery/registry', function (Request $request, Response $response) use ($flextype, $api_sys_messages) { // Get Query Params $query = $request->getQueryParams(); @@ -53,37 +59,50 @@ $app->get('/api/delivery/registry', function (Request $request, Response $respon if ($delivery_registry_token_file_data = $flextype['parser']->decode(Filesystem::read($delivery_registry_token_file_path), 'yaml')) { if ($delivery_registry_token_file_data['state'] === 'disabled' || ($delivery_registry_token_file_data['limit_calls'] !== 0 && $delivery_registry_token_file_data['calls'] >= $delivery_registry_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Fetch registry if ($flextype['registry']->has($id)) { - $data['data']['key'] = $id; - $data['data']['value'] = $flextype['registry']->get($id); + $response_data['data']['key'] = $id; + $response_data['data']['value'] = $flextype['registry']->get($id); + + // Set response code + $response_code = 200; + } else { - $data = []; + $response_data = []; + $response_code = 404; } // Update calls counter Filesystem::write($delivery_registry_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_registry_token_file_data, ['calls' => $delivery_registry_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response - ->withJson($data, 200) + ->withJson($response_data, $response_code) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); diff --git a/src/flextype/endpoints/images/images.php b/src/flextype/endpoints/images/images.php index a6eedf3e..df274bf7 100644 --- a/src/flextype/endpoints/images/images.php +++ b/src/flextype/endpoints/images/images.php @@ -23,6 +23,12 @@ function validate_images_token($token) : bool return Filesystem::has(PATH['site'] . '/tokens/images/' . $token . '/token.yaml'); } +/** + * API sys messages + */ +$api_sys_messages['AccessTokenInvalid'] = ['sys' => ['type' => 'Error', 'id' => 'AccessTokenInvalid'], 'message' => 'The access token you sent could not be found or is invalid.']; +$api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound'], 'message' => 'The resource could not be found.']; + /** * Fetch image * @@ -37,7 +43,7 @@ function validate_images_token($token) : bool * Returns: * Image file */ -$app->get('/api/images/{path:.+}', function (Request $request, Response $response, $args) use ($flextype) { +$app->get('/api/images/{path:.+}', function (Request $request, Response $response, $args) use ($flextype, $api_sys_messages) { // Get Query Params $query = $request->getQueryParams(); @@ -56,7 +62,7 @@ $app->get('/api/images/{path:.+}', function (Request $request, Response $respons if ($delivery_images_token_file_data['state'] === 'disabled' || ($delivery_images_token_file_data['limit_calls'] !== 0 && $delivery_images_token_file_data['calls'] >= $delivery_images_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Update calls counter @@ -69,25 +75,21 @@ $app->get('/api/images/{path:.+}', function (Request $request, Response $respons } return $response - ->withJson([], 404) + ->withJson($api_sys_messages['NotFound'], 404) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) - ->withHeader('Access-Control-Allow-Origin', '*'); - } else { - return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withStatus(404) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); diff --git a/src/flextype/endpoints/management/entries.php b/src/flextype/endpoints/management/entries.php index a22327fa..264948f4 100644 --- a/src/flextype/endpoints/management/entries.php +++ b/src/flextype/endpoints/management/entries.php @@ -15,6 +15,12 @@ use Psr\Http\Message\ServerRequestInterface as Request; use function array_replace_recursive; use function count; +/** + * API sys messages + */ +$api_sys_messages['AccessTokenInvalid'] = ['sys' => ['type' => 'Error', 'id' => 'AccessTokenInvalid'], 'message' => 'The access token you sent could not be found or is invalid.']; +$api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound'], 'message' => 'The resource could not be found.']; + /** * Validate management entries token */ @@ -44,7 +50,7 @@ function validate_access_token($token) : bool * Returns: * An array of entry item objects. */ -$app->get('/api/management/entries', function (Request $request, Response $response) use ($flextype) { +$app->get('/api/management/entries', function (Request $request, Response $response) use ($flextype, $api_sys_messages) { // Get Query Params $query = $request->getQueryParams(); @@ -62,36 +68,44 @@ $app->get('/api/management/entries', function (Request $request, Response $respo if ($management_entries_token_file_data = $flextype['parser']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) { if ($management_entries_token_file_data['state'] === 'disabled' || ($management_entries_token_file_data['limit_calls'] !== 0 && $management_entries_token_file_data['calls'] >= $management_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Fetch entry - $data['data'] = $flextype['entries']->fetch($id, $filter); + $response_data['data'] = $flextype['entries']->fetch($id, $filter); // Set response code - $response_code = count($data['data']) > 0 ? 200 : 404; + $response_code = count($response_data['data']) > 0 ? 200 : 404; // Update calls counter Filesystem::write($management_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($management_entries_token_file_data, ['calls' => $management_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response - ->withJson($data, $response_code) + ->withJson($response_data, $response_code) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); @@ -110,7 +124,7 @@ $app->get('/api/management/entries', function (Request $request, Response $respo * Returns: * Returns the entry item object for the entry item that was just created. */ -$app->post('/api/management/entries', function (Request $request, Response $response) use ($flextype) { +$app->post('/api/management/entries', function (Request $request, Response $response) use ($flextype, $api_sys_messages) { // Get Post Data $post_data = $request->getParsedBody(); @@ -134,12 +148,12 @@ $app->post('/api/management/entries', function (Request $request, Response $resp if ($management_entries_token_file_data['state'] === 'disabled' || ($management_entries_token_file_data['limit_calls'] !== 0 && $management_entries_token_file_data['calls'] >= $management_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Create entry @@ -157,6 +171,14 @@ $app->post('/api/management/entries', function (Request $request, Response $resp // Update calls counter Filesystem::write($management_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($management_entries_token_file_data, ['calls' => $management_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response ->withJson($response_data, $response_code) @@ -164,17 +186,17 @@ $app->post('/api/management/entries', function (Request $request, Response $resp } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); @@ -216,12 +238,12 @@ $app->patch('/api/management/entries', function (Request $request, Response $res if ($management_entries_token_file_data['state'] === 'disabled' || ($management_entries_token_file_data['limit_calls'] !== 0 && $management_entries_token_file_data['calls'] >= $management_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.0'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.00'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Update entry @@ -239,6 +261,14 @@ $app->patch('/api/management/entries', function (Request $request, Response $res // Update calls counter Filesystem::write($management_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($management_entries_token_file_data, ['calls' => $management_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response ->withJson($response_data, $response_code) @@ -246,17 +276,17 @@ $app->patch('/api/management/entries', function (Request $request, Response $res } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); @@ -298,12 +328,12 @@ $app->put('/api/management/entries', function (Request $request, Response $respo if ($management_entries_token_file_data['state'] === 'disabled' || ($management_entries_token_file_data['limit_calls'] !== 0 && $management_entries_token_file_data['calls'] >= $management_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.0'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.00'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Rename entry @@ -322,6 +352,14 @@ $app->put('/api/management/entries', function (Request $request, Response $respo // Update calls counter Filesystem::write($management_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($management_entries_token_file_data, ['calls' => $management_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response ->withJson($response_data, $response_code) @@ -329,17 +367,17 @@ $app->put('/api/management/entries', function (Request $request, Response $respo } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); @@ -381,12 +419,12 @@ $app->put('/api/management/entries/copy', function (Request $request, Response $ if ($management_entries_token_file_data['state'] === 'disabled' || ($management_entries_token_file_data['limit_calls'] !== 0 && $management_entries_token_file_data['calls'] >= $management_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.0'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.00'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Copy entry @@ -405,6 +443,14 @@ $app->put('/api/management/entries/copy', function (Request $request, Response $ // Update calls counter Filesystem::write($management_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($management_entries_token_file_data, ['calls' => $management_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response ->withJson($response_data, $response_code) @@ -412,17 +458,17 @@ $app->put('/api/management/entries/copy', function (Request $request, Response $ } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); }); @@ -453,7 +499,7 @@ $app->delete('/api/management/entries', function (Request $request, Response $re // Validate management and access token if (validate_management_entries_token($token) && validate_access_token($access_token)) { - $management_entries_token_file_path => PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; + $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; $access_token_file_path = PATH['site'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set management and access token file @@ -462,12 +508,12 @@ $app->delete('/api/management/entries', function (Request $request, Response $re if ($management_entries_token_file_data['state'] === 'disabled' || ($management_entries_token_file_data['limit_calls'] !== 0 && $management_entries_token_file_data['calls'] >= $management_entries_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.0'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } if ($access_token_file_data['state'] === 'disabled' || ($access_token_file_data['limit_calls'] !== 0 && $access_token_file_data['calls'] >= $access_token_file_data['limit_calls'])) { - return $response->withJson(['detail' => 'Incorrect authentication credentials.00'], 401); + return $response->withJson($api_sys_messages['AccessTokenInvalid'], 401); } // Delete entry @@ -479,6 +525,14 @@ $app->delete('/api/management/entries', function (Request $request, Response $re // Update calls counter Filesystem::write($management_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($management_entries_token_file_data, ['calls' => $management_entries_token_file_data['calls'] + 1]), 'yaml')); + if ($response_code == 404) { + + // Return response + return $response + ->withJson($api_sys_messages['NotFound'], $response_code) + ->withHeader('Access-Control-Allow-Origin', '*'); + } + // Return response return $response ->withJson($delete_entry, $response_code) @@ -486,16 +540,16 @@ $app->delete('/api/management/entries', function (Request $request, Response $re } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); } return $response - ->withJson(['detail' => 'Incorrect authentication credentials.'], 401) + ->withJson($api_sys_messages['AccessTokenInvalid'], 401) ->withHeader('Access-Control-Allow-Origin', '*'); });