Skip to content

Commit c2c8bfd

Browse files
committed
throw out a Lua exception instead of nginx error logging
1 parent bceb3ef commit c2c8bfd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/ngx_http_lua_control.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ ngx_http_lua_ngx_exit(lua_State *L)
330330
if (ctx->context & NGX_HTTP_LUA_CONTEXT_BODY_FILTER) {
331331

332332
if (rc != NGX_ERROR && rc < 400) {
333-
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "attempt to "
334-
"exit with the code smaller than 400 and not "
335-
"ngx.ERROR");
333+
return luaL_error(L, "attempt to exit with the code smaller "
334+
"than 400 and not ngx.ERROR");
336335
}
337336

338337
ctx->body_exited = 1;
@@ -497,9 +496,10 @@ ngx_http_lua_ffi_exit(ngx_http_request_t *r, int status, u_char *err,
497496
if (ctx->context & NGX_HTTP_LUA_CONTEXT_BODY_FILTER) {
498497

499498
if (status != NGX_ERROR && status < 400) {
500-
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "attempt to "
501-
"exit with the code smaller than 400 and not "
502-
"ngx.ERROR");
499+
*errlen = ngx_snprintf(err, *errlen, "attempt to exit with the "
500+
"code smaller than 400 and not ngx.ERROR")
501+
- err;
502+
return NGX_ERROR;
503503
}
504504

505505
ctx->body_exited = 1;

t/082-body-filter.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ log_level('debug');
1010

1111
repeat_each(2);
1212

13-
plan tests => repeat_each() * (blocks() * 3 + 13);
13+
plan tests => repeat_each() * (blocks() * 3 + 11);
1414

1515
#no_diff();
1616
no_long_string();
@@ -879,9 +879,7 @@ API disabled in the context of body_filter_by_lua*
879879
}
880880
--- request
881881
GET /t
882-
--- response_body
883-
111
884-
--- error_code: 200
882+
--- ignore_response
885883
--- error_log
886884
attempt to exit with the code smaller than 400 and not ngx.ERROR
887885

0 commit comments

Comments
 (0)