aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-31 11:22:14 +0200
committerClément Malléjac <clementmallejac@gmail.com>2018-07-31 17:20:51 +0200
commitb5c8b62d0cdb2be9783ed0e77aced499a833e079 (patch)
treeb521089fb007990fffd2f8a327399cf889cd60b4
parentcfd292fcd7b27d82307383c1e2ccd9fb65eec9e6 (diff)
Returns error in request response
Returns error in request response instead of binder log. Change-Id: I12809591801db5718aa4713034f2bb1801b6bf2d Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp16
-rw-r--r--signal-composer-binding/signal.cpp12
2 files changed, 10 insertions, 18 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 0603656..09f1b30 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -236,10 +236,9 @@ void list(afb_req request)
/// @brief entry point for get requests.
void get(struct afb_req request)
{
- int err = 0, i = 0;
- size_t l = 0;
+ int err = 0;
struct json_object* args = afb_req_json(request), *ans = nullptr,
- *options = nullptr, *error = nullptr, *object = nullptr;
+ *options = nullptr, *error = nullptr;
const char* sig;
// Process about Raw CAN message on CAN bus directly
@@ -253,18 +252,11 @@ void get(struct afb_req request)
ans = Composer::instance().getsignalValue(sig, options);
- l = json_object_array_length(ans);
- if(l) {
- while(i < l) {
- object = json_object_array_get_idx(ans, i++);
- if(json_object_object_get_ex(object, "error", &error))
- break;
- }
- if(error)
+ if (json_object_array_length(ans))
+ if(json_object_object_get_ex(ans, "error", &error))
afb_req_fail(request, "error", json_object_get_string(error));
else
afb_req_success(request, ans, NULL);
- }
else
afb_req_fail(request, "error", "No signals found.");
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index b77ab59..6b2163f 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -370,9 +370,9 @@ json_object * Signal::average(int seconds) const
int nbElt = 0;
std::stringstream errorMsg;
- if(history_.empty() && seconds < 0)
+ if(history_.empty())
{
- errorMsg << "There are no historized values or you requested a negative time interval for that signal: " << id_;
+ errorMsg << "There is no historized values for that signal: " << id_;
return json_object_new_string(errorMsg.str().c_str());
}
@@ -417,9 +417,9 @@ json_object *Signal::minimum(int seconds) const
double min = DBL_MAX;
std::stringstream errorMsg;
- if(history_.empty() && seconds < 0)
+ if(history_.empty())
{
- errorMsg << "There is no historized values or you requested a negative time interval for that signal: " << id_;
+ errorMsg << "There is no historized values for that signal: " << id_;
return json_object_new_string(errorMsg.str().c_str());
}
@@ -464,8 +464,8 @@ json_object * Signal::maximum(int seconds) const
double max = 0.0;
std::stringstream errorMsg;
- if(history_.empty() && seconds < 0) {
- errorMsg << "There is no historized values or you requested a negative time interval for that signal: " << id_;
+ if(history_.empty()) {
+ errorMsg << "There is no historized values for that signal: " << id_;
return json_object_new_string(errorMsg.str().c_str());
}