diff options
| author | 2023-02-14 08:15:38 +0100 | |
|---|---|---|
| committer | 2023-02-14 08:15:43 +0100 | |
| commit | 7e27ccfde8ec9d7d9edb9febdd54796ff3eae97c (patch) | |
| tree | ba88d90c46e7ade02952dccd2d8d1a6e4a79079c | |
| parent | Updated documentation. (diff) | |
| download | snac2-7e27ccfde8ec9d7d9edb9febdd54796ff3eae97c.tar.gz snac2-7e27ccfde8ec9d7d9edb9febdd54796ff3eae97c.tar.xz snac2-7e27ccfde8ec9d7d9edb9febdd54796ff3eae97c.zip | |
Try to show a piece of the error after connecting.
| -rw-r--r-- | activitypub.c | 28 | ||||
| -rw-r--r-- | httpd.c | 2 |
2 files changed, 27 insertions, 3 deletions
diff --git a/activitypub.c b/activitypub.c index f6660db..75b84ec 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1180,7 +1180,22 @@ void process_queue_item(xs_dict *q_item) | |||
| 1180 | /* deliver */ | 1180 | /* deliver */ |
| 1181 | status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, retries == 0 ? 3 : 8); | 1181 | status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, retries == 0 ? 3 : 8); |
| 1182 | 1182 | ||
| 1183 | srv_log(xs_fmt("output message: sent to inbox %s %d", inbox, status)); | 1183 | if (payload && !valid_status(status)) { |
| 1184 | /* in case of error, print a part of the payload, | ||
| 1185 | as it may be informative */ | ||
| 1186 | if (p_size > 24) { | ||
| 1187 | /* trim the message */ | ||
| 1188 | payload[24] = '\0'; | ||
| 1189 | payload = xs_str_cat(payload, "..."); | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | payload = xs_str_wrap_i(" (", payload, ")"); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | if (payload == NULL) | ||
| 1196 | payload = xs_str_new(NULL); | ||
| 1197 | |||
| 1198 | srv_log(xs_fmt("output message: sent to inbox %s %d%s", inbox, status, payload)); | ||
| 1184 | 1199 | ||
| 1185 | if (!valid_status(status)) { | 1200 | if (!valid_status(status)) { |
| 1186 | retries++; | 1201 | retries++; |
| @@ -1377,8 +1392,11 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 1377 | snac snac; | 1392 | snac snac; |
| 1378 | char *v; | 1393 | char *v; |
| 1379 | 1394 | ||
| 1380 | if (i_ctype == NULL) | 1395 | if (i_ctype == NULL) { |
| 1396 | *body = xs_str_new("no content-type"); | ||
| 1397 | *ctype = "text/plain"; | ||
| 1381 | return 400; | 1398 | return 400; |
| 1399 | } | ||
| 1382 | 1400 | ||
| 1383 | if (xs_str_in(i_ctype, "application/activity+json") == -1 && | 1401 | if (xs_str_in(i_ctype, "application/activity+json") == -1 && |
| 1384 | xs_str_in(i_ctype, "application/ld+json") == -1) | 1402 | xs_str_in(i_ctype, "application/ld+json") == -1) |
| @@ -1389,6 +1407,9 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 1389 | 1407 | ||
| 1390 | if (msg == NULL) { | 1408 | if (msg == NULL) { |
| 1391 | srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); | 1409 | srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); |
| 1410 | |||
| 1411 | *body = xs_str_new("JSON error"); | ||
| 1412 | *ctype = "text/plain"; | ||
| 1392 | status = 400; | 1413 | status = 400; |
| 1393 | } | 1414 | } |
| 1394 | 1415 | ||
| @@ -1417,6 +1438,9 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 1417 | 1438 | ||
| 1418 | if (strcmp(s2, v) != 0) { | 1439 | if (strcmp(s2, v) != 0) { |
| 1419 | srv_log(xs_fmt("digest check FAILED")); | 1440 | srv_log(xs_fmt("digest check FAILED")); |
| 1441 | |||
| 1442 | *body = xs_str_new("bad digest"); | ||
| 1443 | *ctype = "text/plain"; | ||
| 1420 | status = 400; | 1444 | status = 400; |
| 1421 | } | 1445 | } |
| 1422 | } | 1446 | } |
| @@ -198,7 +198,7 @@ void httpd_connection(FILE *f) | |||
| 198 | if (status == 404) | 198 | if (status == 404) |
| 199 | body = xs_str_new("<h1>404 Not Found</h1>"); | 199 | body = xs_str_new("<h1>404 Not Found</h1>"); |
| 200 | 200 | ||
| 201 | if (status == 400) | 201 | if (status == 400 && body != NULL) |
| 202 | body = xs_str_new("<h1>400 Bad Request</h1>"); | 202 | body = xs_str_new("<h1>400 Bad Request</h1>"); |
| 203 | 203 | ||
| 204 | if (status == 303) | 204 | if (status == 303) |