Let’s build a full-stack UK weather app using Node + React Part 2: error handling

Code example in this article can be found in my Github Page.

Xiaohan Du
5 min readAug 10, 2020

--

Oops, 404

In Part 1 we scaffolded a basic set up for our UK weather app and successfully fetched and displayed the weather data from Openweathermap API. An important point in part 1 was how user input data was stored in React state and sent to Node. You may have noticed that some errors happened when non-standard UK postcode was entered, thus in part 2 I’m going to show you my thoughts of handling these errors.

Part 3 here.

The error

Let’s take a look at what happens if entering a random postcode in the input field: aa123aa

Error without handling

The error is pretty much self-explanatory: response.result = undefined. Console.log(response) and we can see:

response

Openweathermap API returned a 404 error when a false postcode was entered.

How to handle the…

--

--