MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

better error messages

+7 -26
+1 -1
meson.build
··· 67 67 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 68 68 69 69 version_conf = configuration_data() 70 - version_conf.set('ANT_VERSION', '0.0.6.33') 70 + version_conf.set('ANT_VERSION', '0.0.6.34') 71 71 version_conf.set('ANT_GIT_HASH', git_hash) 72 72 version_conf.set('ANT_BUILD_DATE', build_date) 73 73
+6 -25
src/modules/server.c
··· 6 6 #include <uv.h> 7 7 8 8 #include "ant.h" 9 + #include "config.h" 9 10 #include "runtime.h" 10 11 #include "modules/server.h" 11 12 #include "modules/timer.h" ··· 133 134 static void on_close(uv_handle_t *handle); 134 135 static void send_response(uv_stream_t *client, response_ctx_t *res_ctx); 135 136 136 - typedef struct { 137 - http_server_t *server; 138 - response_ctx_t *res_ctx; 139 - } promise_callback_data_t; 140 137 141 - static jsval_t promise_then_callback(struct js *js, jsval_t *args, int nargs) { 142 - (void)js; 143 - (void)args; 144 - (void)nargs; 145 - // The promise resolved, response should have been sent via res.body() etc 146 - // Mark as sent if not already sent (for cases where handler doesn't call res methods) 147 - // This will be handled by check_pending_responses in the event loop 148 - return js_mkundef(); 149 - } 150 138 151 139 static jsval_t res_status(struct js *js, jsval_t *args, int nargs) { 152 140 if (nargs < 1) return js_mkundef(); ··· 330 318 331 319 jsval_t args[2] = {req, res_obj}; 332 320 result = js_call(server->js, server->handler, args, 2); 321 + if (js_type(result) == JS_PROMISE) return; 333 322 334 323 if (js_type(result) == JS_ERR) { 335 324 fprintf(stderr, "Handler error: %s\n", js_str(server->js, result)); 336 325 res_ctx->status = 500; 337 - res_ctx->body = "Internal Server Error"; 326 + res_ctx->body = "internal server error\nant http v" ANT_VERSION " (" ANT_GIT_HASH ")"; 338 327 res_ctx->content_type = "text/plain"; 339 328 res_ctx->sent = 1; 340 - } else if (js_type(result) == JS_PROMISE) { 341 - jsval_t then_fn = js_get(server->js, result, "then"); 342 - if (js_type(then_fn) != JS_UNDEF) { 343 - jsval_t callback = js_mkfun(promise_then_callback); 344 - jsval_t then_args[1] = {callback}; 345 - js_call(server->js, then_fn, then_args, 1); 346 - } 347 - return; 348 329 } else if (!res_ctx->sent) { 349 330 res_ctx->status = 404; 350 - res_ctx->body = "Not Found"; 331 + res_ctx->body = "not found\nant http v" ANT_VERSION " (" ANT_GIT_HASH ")"; 351 332 res_ctx->content_type = "text/plain"; 352 333 res_ctx->sent = 1; 353 334 } ··· 356 337 } 357 338 358 339 res_ctx->status = 404; 359 - res_ctx->body = "Not Found"; 340 + res_ctx->body = "not found\nant http v" ANT_VERSION " (" ANT_GIT_HASH ")"; 360 341 res_ctx->content_type = "text/plain"; 361 342 res_ctx->sent = 1; 362 343 } ··· 440 421 response_ctx_t *res_ctx = malloc(sizeof(response_ctx_t)); 441 422 if (res_ctx) { 442 423 res_ctx->status = 400; 443 - res_ctx->body = "Bad Request"; 424 + res_ctx->body = "bad request\nant http v" ANT_VERSION " (" ANT_GIT_HASH ")"; 444 425 res_ctx->content_type = "text/plain"; 445 426 res_ctx->sent = 1; 446 427 res_ctx->client_handle = &client->handle;