Fossil SCM

If fossil.fetch()'s beforesend() callback propagates an exception, it is now passed to the onerror() callback and aborts the fetch, rather than being silently ignored.

stephan 2020-12-12 10:01 trunk
Commit 1515f0224dc1af8ea473220505191b23e5722b129dd6c645f04bb1666a54d24b
1 file changed +16 -11
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -70,18 +70,20 @@
7070
header values. When a map is passed on, all of its keys are
7171
lower-cased. When a given header is requested and that header is
7272
set multiple times, their values are (per the XHR docs)
7373
concatenated together with ", " between them.
7474
75
- - beforesend/aftersend: optional callbacks which are called without
76
- arguments immediately before the request is submitted and
77
- immediately after it is received, regardless of success or
78
- error. In the context of the callback, the options object is the
79
- "this". These can be used to, e.g., keep track of in-flight
80
- requests and update the UI accordingly, e.g. disabling/enabling DOM
81
- elements. Any exceptions triggered by beforesend/aftersend are
82
- caught and silently ignored.
75
+ - beforesend/aftersend: optional callbacks which are called
76
+ without arguments immediately before the request is submitted
77
+ and immediately after it is received, regardless of success or
78
+ error. In the context of the callback, the options object is
79
+ the "this". These can be used to, e.g., keep track of in-flight
80
+ requests and update the UI accordingly, e.g. disabling/enabling
81
+ DOM elements. Any exceptions thrown in an beforesend are passed
82
+ to the onerror() handler and cause the fetch() to prematurely
83
+ abort. Exceptions thrown in aftersend are currently silently
84
+ ignored (feature or bug?).
8385
8486
- timeout: integer in milliseconds specifying the XHR timeout
8587
duration. Default = fossil.fetch.timeout.
8688
8789
When an options object does not provide
@@ -91,12 +93,11 @@
9193
default onload/onerror implementations route the data through the
9294
dev console and (for onerror()) through fossil.error(). The default
9395
beforesend/aftersend are no-ops. Individual pages may overwrite
9496
those members to provide default implementations suitable for the
9597
page's use, e.g. keeping track of how many in-flight ajax requests
96
- are pending. Any exceptions thrown in an beforesend/aftersend
97
- handler are current ignored (feature or bug?).
98
+ are pending.
9899
99100
Note that this routine may add properties to the 2nd argument, so
100101
that instance should not be kept around for later use.
101102
102103
Returns this object, noting that the XHR request is asynchronous,
@@ -195,11 +196,15 @@
195196
opt.onload.apply(opt, args);
196197
}catch(e){
197198
opt.onerror(e);
198199
}
199200
};
200
- try{opt.beforesend()}catch(e){/*ignore*/}
201
+ try{opt.beforesend()}
202
+ catch(e){
203
+ opt.onerror(e);
204
+ return;
205
+ }
201206
x.open(opt.method||'GET', url.join(''), true);
202207
if('POST'===opt.method && 'string'===typeof opt.contentType){
203208
x.setRequestHeader('Content-Type',opt.contentType);
204209
}
205210
x.timeout = +opt.timeout || f.timeout;
206211
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -70,18 +70,20 @@
70 header values. When a map is passed on, all of its keys are
71 lower-cased. When a given header is requested and that header is
72 set multiple times, their values are (per the XHR docs)
73 concatenated together with ", " between them.
74
75 - beforesend/aftersend: optional callbacks which are called without
76 arguments immediately before the request is submitted and
77 immediately after it is received, regardless of success or
78 error. In the context of the callback, the options object is the
79 "this". These can be used to, e.g., keep track of in-flight
80 requests and update the UI accordingly, e.g. disabling/enabling DOM
81 elements. Any exceptions triggered by beforesend/aftersend are
82 caught and silently ignored.
 
 
83
84 - timeout: integer in milliseconds specifying the XHR timeout
85 duration. Default = fossil.fetch.timeout.
86
87 When an options object does not provide
@@ -91,12 +93,11 @@
91 default onload/onerror implementations route the data through the
92 dev console and (for onerror()) through fossil.error(). The default
93 beforesend/aftersend are no-ops. Individual pages may overwrite
94 those members to provide default implementations suitable for the
95 page's use, e.g. keeping track of how many in-flight ajax requests
96 are pending. Any exceptions thrown in an beforesend/aftersend
97 handler are current ignored (feature or bug?).
98
99 Note that this routine may add properties to the 2nd argument, so
100 that instance should not be kept around for later use.
101
102 Returns this object, noting that the XHR request is asynchronous,
@@ -195,11 +196,15 @@
195 opt.onload.apply(opt, args);
196 }catch(e){
197 opt.onerror(e);
198 }
199 };
200 try{opt.beforesend()}catch(e){/*ignore*/}
 
 
 
 
201 x.open(opt.method||'GET', url.join(''), true);
202 if('POST'===opt.method && 'string'===typeof opt.contentType){
203 x.setRequestHeader('Content-Type',opt.contentType);
204 }
205 x.timeout = +opt.timeout || f.timeout;
206
--- src/fossil.fetch.js
+++ src/fossil.fetch.js
@@ -70,18 +70,20 @@
70 header values. When a map is passed on, all of its keys are
71 lower-cased. When a given header is requested and that header is
72 set multiple times, their values are (per the XHR docs)
73 concatenated together with ", " between them.
74
75 - beforesend/aftersend: optional callbacks which are called
76 without arguments immediately before the request is submitted
77 and immediately after it is received, regardless of success or
78 error. In the context of the callback, the options object is
79 the "this". These can be used to, e.g., keep track of in-flight
80 requests and update the UI accordingly, e.g. disabling/enabling
81 DOM elements. Any exceptions thrown in an beforesend are passed
82 to the onerror() handler and cause the fetch() to prematurely
83 abort. Exceptions thrown in aftersend are currently silently
84 ignored (feature or bug?).
85
86 - timeout: integer in milliseconds specifying the XHR timeout
87 duration. Default = fossil.fetch.timeout.
88
89 When an options object does not provide
@@ -91,12 +93,11 @@
93 default onload/onerror implementations route the data through the
94 dev console and (for onerror()) through fossil.error(). The default
95 beforesend/aftersend are no-ops. Individual pages may overwrite
96 those members to provide default implementations suitable for the
97 page's use, e.g. keeping track of how many in-flight ajax requests
98 are pending.
 
99
100 Note that this routine may add properties to the 2nd argument, so
101 that instance should not be kept around for later use.
102
103 Returns this object, noting that the XHR request is asynchronous,
@@ -195,11 +196,15 @@
196 opt.onload.apply(opt, args);
197 }catch(e){
198 opt.onerror(e);
199 }
200 };
201 try{opt.beforesend()}
202 catch(e){
203 opt.onerror(e);
204 return;
205 }
206 x.open(opt.method||'GET', url.join(''), true);
207 if('POST'===opt.method && 'string'===typeof opt.contentType){
208 x.setRequestHeader('Content-Type',opt.contentType);
209 }
210 x.timeout = +opt.timeout || f.timeout;
211

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button