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.
Commit
1515f0224dc1af8ea473220505191b23e5722b129dd6c645f04bb1666a54d24b
Parent
f0a86f3cacf2f7d…
1 file changed
+16
-11
+16
-11
| --- src/fossil.fetch.js | ||
| +++ src/fossil.fetch.js | ||
| @@ -70,18 +70,20 @@ | ||
| 70 | 70 | header values. When a map is passed on, all of its keys are |
| 71 | 71 | lower-cased. When a given header is requested and that header is |
| 72 | 72 | set multiple times, their values are (per the XHR docs) |
| 73 | 73 | concatenated together with ", " between them. |
| 74 | 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. | |
| 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?). | |
| 83 | 85 | |
| 84 | 86 | - timeout: integer in milliseconds specifying the XHR timeout |
| 85 | 87 | duration. Default = fossil.fetch.timeout. |
| 86 | 88 | |
| 87 | 89 | When an options object does not provide |
| @@ -91,12 +93,11 @@ | ||
| 91 | 93 | default onload/onerror implementations route the data through the |
| 92 | 94 | dev console and (for onerror()) through fossil.error(). The default |
| 93 | 95 | beforesend/aftersend are no-ops. Individual pages may overwrite |
| 94 | 96 | those members to provide default implementations suitable for the |
| 95 | 97 | 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. | |
| 98 | 99 | |
| 99 | 100 | Note that this routine may add properties to the 2nd argument, so |
| 100 | 101 | that instance should not be kept around for later use. |
| 101 | 102 | |
| 102 | 103 | Returns this object, noting that the XHR request is asynchronous, |
| @@ -195,11 +196,15 @@ | ||
| 195 | 196 | opt.onload.apply(opt, args); |
| 196 | 197 | }catch(e){ |
| 197 | 198 | opt.onerror(e); |
| 198 | 199 | } |
| 199 | 200 | }; |
| 200 | - try{opt.beforesend()}catch(e){/*ignore*/} | |
| 201 | + try{opt.beforesend()} | |
| 202 | + catch(e){ | |
| 203 | + opt.onerror(e); | |
| 204 | + return; | |
| 205 | + } | |
| 201 | 206 | x.open(opt.method||'GET', url.join(''), true); |
| 202 | 207 | if('POST'===opt.method && 'string'===typeof opt.contentType){ |
| 203 | 208 | x.setRequestHeader('Content-Type',opt.contentType); |
| 204 | 209 | } |
| 205 | 210 | x.timeout = +opt.timeout || f.timeout; |
| 206 | 211 |
| --- 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 |