Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
fix(core): Response error code when MAM failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Mar 15, 2019
1 parent 92c1f87 commit 08a5547
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions accelerator/apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ status_t api_receive_mam_message(const iota_client_service_t* const service,
char* payload = calloc(payload_size * 2 + 1, sizeof(char));

trytes_to_ascii(payload_trytes, payload_size, payload);
if (payload == NULL) {
ret = SC_MAM_NOT_FOUND;
goto done;
}
*json_result = payload;

payload = NULL;
Expand Down
17 changes: 8 additions & 9 deletions accelerator/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ status_t set_response_content(status_t ret, char** json_result) {
}

cJSON* json_obj = cJSON_CreateObject();
if (ret == SC_CCLIENT_NOT_FOUND) {
if ((ret & SC_ERROR_MASK) == 0x03) {
http_ret = SC_NOT_FOUND;
cJSON_AddStringToObject(json_obj, "message", "Request not found");
} else if (ret == SC_SERIALIZER_JSON_PARSE) {
} else if ((ret & SC_ERROR_MASK) == 0x07) {
http_ret = SC_BAD_REQUEST;
cJSON_AddStringToObject(json_obj, "message", "Invalid request header");
} else {
Expand Down Expand Up @@ -56,18 +56,17 @@ int main(int, char const**) {
set_options_method_header(res);
})
.get([&](served::response& res, const served::request& req) {
status_t ret = SC_OK;
char* json_result = NULL;

api_receive_mam_message(&service, req.params["bundle"].c_str(),
&json_result);
ret = api_receive_mam_message(&service, req.params["bundle"].c_str(),
&json_result);
ret = set_response_content(ret, &json_result);

res.set_header("Content-Type", "application/json");
res.set_header("Access-Control-Allow-Origin", "*");
if (!json_result) {
res.set_status(SC_NOT_FOUND);
} else {
res << json_result;
}
res.set_status(ret);
res << json_result;
});

/**
Expand Down

0 comments on commit 08a5547

Please sign in to comment.