File tree 2 files changed +0
-31
lines changed
04-promise-error-handling
2 files changed +0
-31
lines changed Original file line number Diff line number Diff line change 10
10
document . head . append ( script ) ;
11
11
} ) ;
12
12
}
13
-
14
- class HttpError extends Error {
15
- constructor ( response ) {
16
- super ( `${ response . status } for ${ response . url } ` ) ;
17
- this . name = 'HttpError' ;
18
- this . response = response ;
19
- }
20
- }
21
-
22
- function loadJson ( url ) {
23
- return fetch ( url )
24
- . then ( response => {
25
- if ( response . status == 200 ) {
26
- return response . json ( ) ;
27
- } else {
28
- throw new HttpError ( response ) ;
29
- }
30
- } )
31
- }
32
13
</ script >
33
14
34
15
< style >
Original file line number Diff line number Diff line change 1
1
< script >
2
- function loadScript ( src ) {
3
- return new Promise ( function ( resolve , reject ) {
4
- let script = document . createElement ( 'script' ) ;
5
- script . src = src ;
6
-
7
- script . onload = ( ) => resolve ( script ) ;
8
- script . onerror = ( ) => reject ( new Error ( "Script load error: " + src ) ) ;
9
-
10
- document . head . append ( script ) ;
11
- } ) ;
12
- }
13
-
14
2
class HttpError extends Error {
15
3
constructor ( response ) {
16
4
super ( `${ response . status } for ${ response . url } ` ) ;
You can’t perform that action at this time.
0 commit comments