Handling Errors in Node-RED Flows

Although it’s great when everything goes according to plan, sometimes it doesn’t. One of the downsides of programming with Node-RED is that it can be difficult to track down problems when they occur. In this section, we’ll explore a few ways the book-search API from the last section might fail and how you can investigate and mitigate these failures.

Triggering an Error

To begin, let’s see what happens when the API caller omits the q query parameter. In your terminal, use curl with the -i and -v flags like so to include HTTP headers and produce verbose output:

 $ ​​curl​​ ​​-i​​ ​​-v​​ ​​localhost:1880/search
 * Trying 127.0.0.1...
 * Connected to localhost (127.0.0.1) port 1880 (​#0)
 > GET /search HTTP/1.1 ...

Get Node.js 8 the Right Way now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.