mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-05-31 00:00:07 +08:00
feature #239: add enumeration style object for error codes
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## 2.2.0
|
||||
|
||||
- Feature #239: add enumeration style object for error codes
|
||||
|
||||
## 2.1.1
|
||||
|
||||
- Fixed #224: response type "arraybuffer" and "blob" not working on browser platform
|
||||
|
||||
@@ -292,7 +292,7 @@ cordova.plugin.http.post('https://google.com/', {
|
||||
```
|
||||
|
||||
#### failure
|
||||
The error function receives a response object with 4 properties: status, error, url, and headers (url and headers being optional). **status** is the HTTP response code as numeric value. **error** is the error response from the server as a string. **url** is the final URL obtained after any redirects as a string. **headers** is an object with the headers. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase.
|
||||
The error function receives a response object with 4 properties: status, error, url, and headers (url and headers being optional). **status** is a HTTP response code or an internal error code. Positive values are HTTP status codes whereas negative values do represent internal error codes. **error** is the error response from the server as a string or an internal error message. **url** is the final URL obtained after any redirects as a string. **headers** is an object with the headers. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase.
|
||||
|
||||
Here's a quick example:
|
||||
|
||||
@@ -307,6 +307,8 @@ Here's a quick example:
|
||||
}
|
||||
```
|
||||
|
||||
:warning: An enumeration style object is exposed as `cordova.plugin.http.ErrorCode`. You can use it to check against internal error codes.
|
||||
|
||||
### get<a name="get"></a>
|
||||
Execute a GET request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-advanced-http",
|
||||
"version": "2.1.1",
|
||||
"version": "2.2.0",
|
||||
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
|
||||
"scripts": {
|
||||
"updatecert": "node ./scripts/update-e2e-server-cert.js && node ./scripts/update-e2e-client-cert.js",
|
||||
|
||||
@@ -147,6 +147,10 @@ describe('Advanced HTTP public interface', function () {
|
||||
it('throws an Error when you try to configure global option for following redirects with a string', () => {
|
||||
(function () { http.setFollowRedirect('myString'); }).should.throw(messages.INVALID_FOLLOW_REDIRECT_VALUE);
|
||||
});
|
||||
|
||||
it('exposes an enumeration style object with mappings for the error codes', () => {
|
||||
Object.keys(http.ErrorCode).forEach(key => http.ErrorCode[key].should.be.a('number'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('URL util', function () {
|
||||
|
||||
+12
-2
@@ -1,5 +1,14 @@
|
||||
module.exports = function init(exec, cookieHandler, urlUtil, helpers, globalConfigs) {
|
||||
const publicInterface = {
|
||||
var ErrorCode = {
|
||||
Generic: -1,
|
||||
SslException: -2,
|
||||
ServerNotFound: -3,
|
||||
Timeout: -4,
|
||||
UnsupportedUrl: -5,
|
||||
NotConnected: -6,
|
||||
};
|
||||
|
||||
var publicInterface = {
|
||||
getBasicAuthHeader: getBasicAuthHeader,
|
||||
useBasicAuth: useBasicAuth,
|
||||
getHeaders: getHeaders,
|
||||
@@ -28,7 +37,8 @@ module.exports = function init(exec, cookieHandler, urlUtil, helpers, globalConf
|
||||
delete: del,
|
||||
head: head,
|
||||
uploadFile: uploadFile,
|
||||
downloadFile: downloadFile
|
||||
downloadFile: downloadFile,
|
||||
ErrorCode: ErrorCode
|
||||
};
|
||||
|
||||
function getBasicAuthHeader(username, password) {
|
||||
|
||||
Reference in New Issue
Block a user