mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-05-31 00:00:07 +08:00
[Browser] Fixing error propagation in setHeaders
If the headers contain certain special characters (€, “, ≠, ∑, †, Ω etc..), calling the setHeaders method will throw an "Value is not a valid ByteString" error which unfortunately is neither propagated to the caller of the http-plugin, nor is the xhr request cancelled in this case. By wrapping the setHeader-call into a try/catch, and fail the xhr request in case of an error, we make sure the caller of the http-plugin will receive a proper error and the xhr request gets canceled.
This commit is contained in:
committed by
GitHub
parent
5b8f20e1c4
commit
935e7d6ba3
Vendored
+10
-1
@@ -237,7 +237,16 @@ function sendRequest(method, withData, opts, success, failure) {
|
||||
// we can't set connect timeout and read timeout separately on browser platform
|
||||
xhr.timeout = readTimeout * 1000;
|
||||
|
||||
setHeaders(xhr, headers);
|
||||
try {
|
||||
setHeaders(xhr, headers);
|
||||
} catch(error) {
|
||||
return onFail({
|
||||
status: -8,
|
||||
error: error,
|
||||
url: url,
|
||||
headers: headers
|
||||
});
|
||||
}
|
||||
|
||||
xhr.onerror = function () {
|
||||
return onFail(createXhrFailureObject(xhr));
|
||||
|
||||
Reference in New Issue
Block a user