diff options
author | Michael McVady <femtonaut@gmail.com> | 2023-01-02 09:56:24 -0600 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2023-01-02 09:56:24 -0600 |
commit | 0050e1d3960d4ee6cdeca4e20bea5ecb05c35af2 (patch) | |
tree | 43abe251e36af798848a16278c29ddbd970c57e5 | |
parent | f77705780a552ef9c8a3fcd97406400180ca1f82 (diff) |
Template JSON error responses
-rw-r--r-- | assets/error.json | 1 | ||||
-rw-r--r-- | src/clog.c | 17 |
2 files changed, 9 insertions, 9 deletions
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" @@ -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; |