From 0050e1d3960d4ee6cdeca4e20bea5ecb05c35af2 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Mon, 2 Jan 2023 09:56:24 -0600 Subject: Template JSON error responses --- assets/error.json | 1 + src/clog.c | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 assets/error.json diff --git a/assets/error.json b/assets/error.json new file mode 100644 index 0000000..94d600d --- /dev/null +++ b/assets/error.json @@ -0,0 +1 @@ +"%s" diff --git a/src/clog.c b/src/clog.c index 67c6b09..4a2d09a 100644 --- a/src/clog.c +++ b/src/clog.c @@ -44,10 +44,9 @@ int render_posts_json(struct post_request *); static void process_md_output(const MD_CHAR *, MD_SIZE size, void *); static int render_md(const char *, struct kore_buf *); -static const char *database = "db"; -// FIXME: quotes for JSON error output; extra quotes in HTML -static const char *req_err = "\"There was an error processing the request.\""; static const char *accept_json = "application/json"; +static const char *database = "db"; +static const char *req_err = "There was an error processing the request."; void post_request_init(struct post_request *post_req) { @@ -306,10 +305,10 @@ render_posts_json(struct post_request *post_req) if (err == KORE_RESULT_ERROR) { post_req->resp_status = HTTP_STATUS_INTERNAL_ERROR; - kore_buf_append( + kore_buf_appendf( post_req->resp_buf, - req_err, - strlen(req_err) + (const char *) asset_error_json, + req_err ); kore_pgsql_logerror(&sql); goto out; @@ -343,10 +342,10 @@ render_posts_json(struct post_request *post_req) if (err == KORE_RESULT_ERROR) { post_req->resp_status = HTTP_STATUS_INTERNAL_ERROR; - kore_buf_append( + kore_buf_appendf( post_req->resp_buf, - req_err, - strlen(req_err) + (const char *) asset_error_json, + req_err ); kore_pgsql_logerror(&sql); goto out; -- cgit v1.2.3