File tree Expand file tree Collapse file tree 2 files changed +0
-31
lines changed
04-promise-error-handling Expand file tree Collapse file tree 2 files changed +0
-31
lines changed Original file line number Diff line number Diff line change 1010 document . head . append ( script ) ;
1111 } ) ;
1212}
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- }
3213</ script >
3314
3415< style >
Original file line number Diff line number Diff line change 11< 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-
142class HttpError extends Error {
153 constructor ( response ) {
164 super ( `${ response . status } for ${ response . url } ` ) ;
You can’t perform that action at this time.
0 commit comments