Skip to content

Commit

Permalink
Merge pull request #37 from epsilla-cloud/json-parsing
Browse files Browse the repository at this point in the history
add payload parsing error check;
  • Loading branch information
eric-epsilla authored Aug 18, 2023
2 parents a1165c1 + ace5dcb commit fd0432b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions engine/server/web_server/web_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ class WebController : public oatpp::web::server::api::ApiController {

ENDPOINT("POST", "/api/load", LoadDB, BODY_STRING(String, body)) {
vectordb::Json parsedBody;
parsedBody.LoadFromString(body);
auto valid = parsedBody.LoadFromString(body);
if (!valid) {
dto->statusCode = Status::CODE_400.code;
dto->message = "Invalid payload.";
return createDtoResponse(Status::CODE_400, dto);
}

std::string db_path = parsedBody.GetString("path");
std::string db_name = parsedBody.GetString("name");
int64_t init_table_scale = InitTableScale;
Expand Down Expand Up @@ -140,7 +146,13 @@ class WebController : public oatpp::web::server::api::ApiController {
auto dto = StatusDto::createShared();

vectordb::Json parsedBody;
parsedBody.LoadFromString(body);
auto valid = parsedBody.LoadFromString(body);
if (!valid) {
dto->statusCode = Status::CODE_400.code;
dto->message = "Invalid payload.";
return createDtoResponse(Status::CODE_400, dto);
}

vectordb::engine::meta::TableSchema table_schema;
if (!parsedBody.HasMember("name")) {
dto->statusCode = Status::CODE_400.code;
Expand Down

0 comments on commit fd0432b

Please sign in to comment.