From e477e8d1840ad20329b712d43c36fcaebfdbcff3 Mon Sep 17 00:00:00 2001 From: lixiumei Date: Wed, 1 Dec 2021 16:23:32 +0800 Subject: [PATCH] Fix http error code --- ft/node_api_test.robot | 2 +- plugins/restful/http.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ft/node_api_test.robot b/ft/node_api_test.robot index e3fb0819..0b425471 100644 --- a/ft/node_api_test.robot +++ b/ft/node_api_test.robot @@ -135,7 +135,7 @@ Get setting from a node that has never been set, it should return failure GET /api/v2/node/setting?node_id=${driver_node_id} - Integer response status 404 + Integer response status 200 Integer response body error ${ERR_NODE_SETTING_NOT_EXIST} Del Node ${driver_node_id} diff --git a/plugins/restful/http.c b/plugins/restful/http.c index aa99f44b..0c75b931 100644 --- a/plugins/restful/http.c +++ b/plugins/restful/http.c @@ -147,16 +147,19 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content) switch (code) { case NEU_ERR_SUCCESS: + case NEU_ERR_NODE_SETTING_NOT_FOUND: status = NNG_HTTP_STATUS_OK; break; case NEU_ERR_EINTERNAL: status = NNG_HTTP_STATUS_INTERNAL_SERVER_ERROR; break; - case NEU_ERR_DECODE_TOKEN: case NEU_ERR_EXPIRED_TOKEN: case NEU_ERR_VALIDATE_TOKEN: case NEU_ERR_INVALID_TOKEN: + status = NNG_HTTP_STATUS_FORBIDDEN; + break; case NEU_ERR_NEED_TOKEN: + case NEU_ERR_DECODE_TOKEN: case NEU_ERR_INVALID_USER_OR_PASSWORD: status = NNG_HTTP_STATUS_UNAUTHORIZED; break; @@ -170,7 +173,6 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_NODE_NOT_EXIST: case NEU_ERR_GRP_CONFIG_NOT_EXIST: case NEU_ERR_TAG_NOT_EXIST: - case NEU_ERR_NODE_SETTING_NOT_FOUND: case NEU_ERR_GRP_NOT_SUBSCRIBE: status = NNG_HTTP_STATUS_NOT_FOUND; break;