File tree Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Expand file tree Collapse file tree 4 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ $ npm start
53
53
npm install --save-dev @babel/core
54
54
npm install --save-dev @babel/plugin-transform-runtime
55
55
npm install --save @babel/runtime
56
+ npm install --save parcel
56
57
```
57
58
58
59
* Create _ .babelrc_ on _ rootDir_
@@ -95,6 +96,8 @@ showBooks();
95
96
### 2. Now we are going to transform this code into async / await style.
96
97
97
98
``` diff
99
+ + import "regenerator-runtime/runtime";
100
+
98
101
- function showBooks() {
99
102
+ async function showBooks() {
100
103
const url = 'http://localhost:8000/api/books/';
@@ -205,7 +208,7 @@ showBooks()
205
208
206
209
``` javascript src/api/BookApiClient.js
207
210
export class BookApiClient {
208
- async fetchUser () {
211
+ async fetchBooks () {
209
212
const url = ' http://localhost:8000/api/books/' ;
210
213
const response = await fetch (url);
211
214
return await response .json ();
Original file line number Diff line number Diff line change 15
15
"author" : " Jaime Salas" ,
16
16
"license" : " MIT" ,
17
17
"devDependencies" : {
18
- "babel-plugin-transform-runtime" : " ^6.23.0" ,
19
- "babel-runtime" : " ^6.26.0" ,
20
- "parcel" : " ^1.8.1"
18
+ "@babel/core" : " ^7.8.4" ,
19
+ "@babel/plugin-transform-runtime" : " ^7.8.3" ,
20
+ "@babel/runtime" : " ^7.8.4" ,
21
+ "parcel" : " ^1.12.4"
21
22
}
22
23
}
Original file line number Diff line number Diff line change
1
+ import "regenerator-runtime/runtime" ;
1
2
// async function showBooks() {
2
3
// const url = 'http://localhost:8000/api/books/';
3
4
// const response = await fetch(url);
Original file line number Diff line number Diff line change @@ -53,12 +53,16 @@ export async function showBooks(url) {
53
53
+ return body;
54
54
}
55
55
```
56
+
56
57
* Automatically rejects the promise, because of 'throw Error'
58
+
57
59
* Now here we have two different scenarios:
60
+
58
61
``` javascript
59
62
const url = ` http://localhost:8000/api/boos/` ; // Wrong url. //
60
63
const url2 = ` http://localhost:8000/api/books/5
61
64
` ` `
65
+
62
66
* The first one no internal route it' s handle by our code (no controller responds to that route). In this case there is not response error handle from
63
67
64
68
* In the second case, the response it' s handle from our controller' s code sending to us a 500.
You can’t perform that action at this time.
0 commit comments