Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RestClient.js
- async getData() {
- const response = await fetch(url);
- if (response.status != 200) {
- throw "Server error (" + response.status + ")";
- }
- const data = await response.json();
- if (data.error) {
- throw data.error;
- }
- return data;
- }
- // Outside class
- async myMethod() {
- try {
- const data = await restClient.getData();
- }
- catch (e) {
- console.log('ERROR: ', e)
- }
- console.log('Data recieved:', data);
- }
- otherMethod() {
- myMethod();
- console.log(this.causes.an.error); // This error will be caught by the catch block from myMethod
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement