Extensions to Promise and Bluebird
Using
- bluebird
- promise-polyfill (polyfill)
- and implement default error handling and get-methods
bower install https://github.com/FCOO/promise-get.git --save
http://FCOO.github.io/promise-get/demo/
A default error handler is added to Promise
Promise.defaultErrorHandler [function( errorObject: ERROR_OBJECT )]
ERROR_OBJECT = {
name : "Error",
status : INTEGER,
message : STRING,
text : STRING,
statusText: STRING
}
//message = text = statusText
Every Promise that fails and don't have a .catch will end in Promise.defaultErrorHandler
Promise.defaultPrefetch = function(url, options): To be called before ALL fetch
Promise.defaultFinally = function(): To be called as finally for ALL Promise.get
Promise.get( url, options[, resolve[, reject[, finally]]] )
Promise.getText( url, options[, resolve[, reject[, finally]]] ) //Same as Promise.get with format = 'text'
Promise.getJSON( url, options[, resolve[, reject[, finally]]] ); //Same as Promise.get with format = 'json'
Promise.getYAML( url, options[, resolve[, reject[, finally]]] ); //Same as Promise.get with format = 'yaml'
Promise.getXML( url, options[, resolve[, reject[, finally]]] ); //Same as Promise.get with format = 'xml'
function( response )
function( errorObject: ERROR_OBJECT )
function()
| Id | Type | Default | Description |
|---|---|---|---|
resolve |
function( response ) |
null |
Alternative for parameter resolve |
done |
function( response ) |
null |
Alternative for parameter resolve |
reject |
function( errorObject: ERROR_OBJECT ) |
null |
Alternative for parameter reject |
fail |
function( errorObject: ERROR_OBJECT ) |
null |
Alternative for parameter reject |
finally |
function() |
null |
Alternative for parameter finally |
always |
function() |
null |
Alternative for parameter finally |
retries |
number |
0 |
Number Alternative for parameter finally |
retryDelay |
number |
0 |
ms between retries |
format |
string |
"text/plain" |
Format |
useDefaultErrorHandler |
boolean |
true |
If true the default error handler is also called even if a reject-function is given. {reject: null, useDefaultErrorHandler:false} => No error cached |
headers etc. |
Standard options for fetch |
This plugin is licensed under the MIT license.
Copyright (c) 2017 FCOO
NielsHolt nho@fcoo.dk