diff --git a/src/modules/http/inc/httpResp.h b/src/modules/http/inc/httpResp.h index d4a0a41b85..4868d4c688 100644 --- a/src/modules/http/inc/httpResp.h +++ b/src/modules/http/inc/httpResp.h @@ -35,6 +35,7 @@ extern const char *httpRespTemplate[]; void httpSendErrorResp(HttpContext *pContext, int errNo); void httpSendErrorRespWithDesc(HttpContext *pContext, int errNo, char *desc); void httpSendTaosdErrorResp(HttpContext *pContext, int errCode); +void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg); void httpSendSuccResp(HttpContext *pContext, char *desc); void httpSendOptionResp(HttpContext *pContext, char *desc); diff --git a/src/modules/http/src/httpResp.c b/src/modules/http/src/httpResp.c index 186f10ff6c..3bea8d4ac3 100644 --- a/src/modules/http/src/httpResp.c +++ b/src/modules/http/src/httpResp.c @@ -18,6 +18,7 @@ #include #include "httpCode.h" #include "httpJson.h" +#include "taosmsg.h" extern char *tsError[]; @@ -186,6 +187,22 @@ void httpSendTaosdErrorResp(HttpContext *pContext, int errCode) { httpSendErrResp(pContext, httpCode, "Bad Request", errCode, tsError[errCode]); } +void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg) { + int httpCode = 400; + char temp[512] = {0}; + int len = sprintf(temp, "invalid SQL: %s", errMsg); + + for (int i = 0; i < len; ++i) { + if (temp[i] == '\"') { + temp[i] = '\''; + } else if (temp[i] == '\n') { + temp[i] = ' '; + } else {} + } + + httpSendErrResp(pContext, httpCode, "Bad Request", TSDB_CODE_INVALID_SQL, temp); +} + void httpSendSuccResp(HttpContext *pContext, char *desc) { char head[1024] = {0}; char body[1024] = {0}; diff --git a/src/modules/http/src/httpSql.c b/src/modules/http/src/httpSql.c index 91e355ba15..10aaa1017b 100644 --- a/src/modules/http/src/httpSql.c +++ b/src/modules/http/src/httpSql.c @@ -238,10 +238,15 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { if (code < 0) { SSqlObj *pObj = (SSqlObj *)result; - httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d, sqlObj:%p", - pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj); - - httpSendTaosdErrorResp(pContext, -code); + if (-code == TSDB_CODE_INVALID_SQL) { + httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d:invalidsql, sqlObj:%p, error:%s", + pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj, pObj->cmd.payload); + httpSendTaosdInvalidSqlErrorResp(pContext, pObj->cmd.payload); + } else { + httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d, sqlObj:%p", + pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj); + httpSendTaosdErrorResp(pContext, -code); + } return; }