botblock / BotBlock.org

BotBlock - The List of Discord Bot Lists and Services
https://botblock.org/
Mozilla Public License 2.0
28 stars 8 forks source link

Single global error method #8

Closed MattIPv4 closed 4 years ago

MattIPv4 commented 4 years ago

Website/API Suggestion

Description

The beginnings of this already exist in src/Util/handleError.js but currently this only handles logging the error to the database.

It would be great if this also handled sending the correct response to the web request so that we can reduce code duplication on all routes that catch errors.

This needs to consider that website routes will want an HTML 500 response but for all API routes, they will expect a JSON response.

Example website usage: src/Routes/Lists.js#L44-L45 Example API usage: src/Routes/API.js#L92-L97

Why

Code duplication is a pain and we want to ensure all errors across the site return a consistent response (API should have a consistent JSON response too).