summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);