Checking fetch for error

why is this so hard

Published June 13, 2024

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

Adapting to new mediums

2024-06-09

Next

How to use pako with vite javascript string encoding is simply insane

2024-06-14

labnotes

Previously

Chromadb on fly.io adding some auth

2024-05-30

Next

Installing a go binary right from the source

2024-06-16