details: https://github.com/nginx/njs/commit/48070f44bd9d44dfd92a8f7873c38bf252d53b45 branches: master commit: 48070f44bd9d44dfd92a8f7873c38bf252d53b45 user: Zhidao HONG <z.h...@f5.com> date: Fri, 11 Apr 2025 21:47:52 +0800 description: Fetch: generalize ngx_js_http_error().
Refactored to support both njs and QuickJS, which have different error formats when throwing exceptions. --- nginx/ngx_js_fetch.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/nginx/ngx_js_fetch.c b/nginx/ngx_js_fetch.c index a803ab4c..2db73904 100644 --- a/nginx/ngx_js_fetch.c +++ b/nginx/ngx_js_fetch.c @@ -156,17 +156,6 @@ struct ngx_js_http_s { }; - - -#define ngx_js_http_error(http, fmt, ...) \ - do { \ - njs_vm_error((http)->vm, fmt, ##__VA_ARGS__); \ - njs_vm_exception_get((http)->vm, \ - njs_value_arg(&(http)->response_value)); \ - ngx_js_http_fetch_done(http, &(http)->response_value, NJS_ERROR); \ - } while (0) - - static njs_int_t ngx_js_method_process(njs_vm_t *vm, ngx_js_request_t *r); static njs_int_t ngx_js_headers_inherit(njs_vm_t *vm, ngx_js_headers_t *headers, ngx_js_headers_t *orig); @@ -1330,6 +1319,26 @@ failed: } +static void +ngx_js_http_error(ngx_js_http_t *http, const char *fmt, ...) +{ + u_char *p, *end; + va_list args; + u_char err[NGX_MAX_ERROR_STR]; + + end = err + NGX_MAX_ERROR_STR - 1; + + va_start(args, fmt); + p = njs_vsprintf(err, end, fmt, args); + *p = '\0'; + va_end(args); + + njs_vm_error(http->vm, (const char *) err); + njs_vm_exception_get(http->vm, njs_value_arg(&http->response_value)); + ngx_js_http_fetch_done(http, &http->response_value, NJS_ERROR); +} + + static void ngx_js_resolve_handler(ngx_resolver_ctx_t *ctx) { _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel