aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-10 19:38:32 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-10 19:38:32 +0200
commit0a8f8f784646254d9b71e928e930003f82d89603 (patch)
tree65e8ab1476485b49268c66ddbfc70f982bbfdb40
parentda61b6ea09f77ea5a8ff6cb79b440db858980211 (diff)
subcall: adds an error function
Change-Id: I9f766c4b880cc741392e5c33b58a2723b5a6f4ef Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-subcall.c12
-rw-r--r--src/afb-subcall.h1
2 files changed, 12 insertions, 1 deletions
diff --git a/src/afb-subcall.c b/src/afb-subcall.c
index bf641738..6566b5b2 100644
--- a/src/afb-subcall.c
+++ b/src/afb-subcall.c
@@ -159,13 +159,23 @@ static void subcall_subcall(struct afb_subcall *subcall, const char *api, const
afb_subcall(&subcall->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_subcall_req_itf, .closure = subcall });
}
+void afb_subcall_internal_error(void (*callback)(void*, int, struct json_object*), void *closure)
+{
+ static struct json_object *obj;
+
+ if (obj == NULL)
+ obj = afb_msg_json_reply_error("failed", "internal error", NULL, NULL);
+
+ callback(closure, 1, obj);
+}
+
void afb_subcall(struct afb_context *context, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure, struct afb_req req)
{
struct afb_subcall *subcall;
subcall = calloc(1, sizeof *subcall);
if (subcall == NULL) {
- callback(closure, 1, afb_msg_json_reply_error("failed", "out of memory", NULL, NULL));
+ afb_subcall_internal_error(callback, closure);
return;
}
diff --git a/src/afb-subcall.h b/src/afb-subcall.h
index 8fbc4ad8..0de51dae 100644
--- a/src/afb-subcall.h
+++ b/src/afb-subcall.h
@@ -23,4 +23,5 @@ struct json_object;
extern void afb_subcall(struct afb_context *context, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure, struct afb_req req);
+extern void afb_subcall_internal_error(void (*callback)(void*, int, struct json_object*), void *closure);