@@ -60,6 +60,10 @@ http {
6060 js_content test.broken_response;
6161 }
6262
63+ location /broken_catch {
64+ js_content test.broken_catch;
65+ }
66+
6367 location /body {
6468 js_content test.body;
6569 }
@@ -234,6 +238,38 @@ $t->write_file('test.js', <<EOF);
234238 return process_errors(r, tests);
235239 }
236240
241+ function process_errors_catch(r, tests) {
242+ var results = [];
243+
244+ var sync_catch = 'sync';
245+
246+ tests.forEach(args => {
247+ ngx.fetch.apply(r, args)
248+ .then(reply => {
249+ r.return(400, '["unexpected then"]');
250+ })
251+ .catch(e => {
252+ results.push(sync_catch);
253+
254+ if (results.length == tests.length) {
255+ r.return(200, JSON.stringify(results));
256+ }
257+ })
258+ })
259+
260+ sync_catch = 'async';
261+ }
262+
263+ function broken_catch(r) {
264+ var tests = [
265+ ['http://127.0.0.1:1/loc'],
266+ ['http://127.0.0.1:80800/loc'],
267+ [Symbol.toStringTag],
268+ ];
269+
270+ return process_errors_catch(r, tests);
271+ }
272+
237273 function chain(r) {
238274 var results = [];
239275 var reqs = [
@@ -428,15 +464,15 @@ $t->write_file('test.js', <<EOF);
428464 r.return(c, `\$ {v.request_method}:\$ {bar}:\$ {body}`);
429465 }
430466
431- export default {njs: test_njs, body, broken, broken_response, body_special ,
432- chain, chunked_ok, chunked_fail, header, header_iter ,
433- host_header, multi, loc, property, body_content_length ,
434- user_agent_header };
467+ export default {njs: test_njs, body, broken, broken_response, broken_catch ,
468+ body_special, chain, chunked_ok, chunked_fail, header,
469+ header_iter, host_header, multi, loc, property,
470+ body_content_length, user_agent_header };
435471EOF
436472
437473$t -> try_run(' no njs.fetch' );
438474
439- $t -> plan(40 );
475+ $t -> plan(41 );
440476
441477$t -> run_daemon(\&http_daemon, port(8082));
442478$t -> waitforsocket(' 127.0.0.1:' . port(8082));
@@ -495,6 +531,8 @@ is(get_json('/multi'),
495531like(http_get(' /multi?throw=1' ), qr / 500/ s , ' fetch destructor' );
496532like(http_get(' /broken' ), qr / 200/ s , ' fetch broken' );
497533like(http_get(' /broken_response' ), qr / 200/ s , ' fetch broken response' );
534+ like(http_get(' /broken_catch' ), qr /\[ "async","async","async"]$ / s ,
535+ ' fetch broken catch' );
498536like(http_get(' /chunked_ok' ), qr / 200/ s , ' fetch chunked ok' );
499537like(http_get(' /chunked_fail' ), qr / 200/ s , ' fetch chunked fail' );
500538like(http_get(' /chain' ), qr / 200 OK.*SUCCESS$ / s , ' fetch chain' );
0 commit comments