Last active
August 14, 2018 02:49
-
-
Save vasilionjea/af7c25e8939a66416d5a1ac5af3978d5 to your computer and use it in GitHub Desktop.
Ember Conccurency - Error Handling
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
import Ember from 'ember'; | |
import { task } from 'ember-concurrency'; | |
function fetchReject(type) { | |
return new Promise(function(resolve, reject) { | |
Ember.run.later(() => reject('rejected reason'), 1000); | |
}); | |
} | |
export default Ember.Controller.extend({ | |
appName: 'Ember Conccurency - Error Handling', | |
actions: { | |
myTask() { | |
this.get('myTask') | |
.perform() | |
.then(() => console.log('success: task is a success')) | |
.catch(e => console.log('catch 2:', e)); | |
}, | |
myBuggyTask() { | |
this.get('myBuggyTask') | |
.perform() | |
.then(() => console.log('success: task is a success')) | |
.catch(e => console.log('catch 2:', e)); | |
}, | |
}, | |
myTask: task(function*() { | |
try { | |
const response = yield fetchReject(); | |
console.log(response); | |
} catch (e) { | |
console.log('catch 1:', e); | |
// You must do one of these if you want the error to get | |
// "piped" through the promise chain in the action. | |
// | |
// yield Promise.reject(e); | |
// return Promise.reject(e); | |
throw e; | |
} | |
}).drop(), | |
myBuggyTask: task(function*() { | |
try { | |
const response = yield fetchReject(); | |
} catch (e) { | |
console.log('catch 1:', e); | |
} | |
}).drop(), | |
}); |
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
{ | |
"version": "0.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-concurrency": "0.8.19" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment