labnotes

Checking fetch for error

why is this so hard

tags
javascript

Contents

I can never remember how to actually to error checking with fetch. Maybe I'm just slow.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  async function serverDown() {
      try {
          return fetch( "http://localhost:1234" )
              .catch( (e) => {
                  console.log( "Promise error" );
                  console.log(e);
              })
      } catch( e ) {
          console.log( "Exception error" );
          console.log( e );
      }
  }

  console.log( "Starting" );
  await serverDown();
  console.log( "Done" )

To explore:

1
  npx live-server

And if you open the console:

A more detailed walk through can help you figure out what style works better for you.

Previously

fragments

Adapting to new mediums

tags

Next

howto

How to use pako with vite

javascript string encoding is simply insane

tags
javascript
pako