Last active
August 29, 2015 14:00
-
-
Save joecliff/7154d1a4a2b43ace31c2 to your computer and use it in GitHub Desktop.
recover from error in q.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Q = require('q'); | |
function prepare(data) { | |
// return Q(data); | |
return Q.reject(new Error('special error1')); | |
} | |
function judgeError(err) { | |
console.log('catch: ', err); | |
if (~err.message.indexOf('special error').length) { | |
//simulate calling other async function | |
return Q('data recovered from error'); | |
} | |
throw err; | |
} | |
function handleResult(data) { | |
console.log('get data: ', data); | |
} | |
prepare('normal data').catch(judgeError).then(handleResult).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment