Add error handling in the database query function. When a database error
occurs, it is logged in the server and a plain text response is returned to the
user.
Implement building of SQL queries inside the API, which removes the
need to have stored functions/procedures on the database, since the former
approach is not flexible or efficient to maintain/extend.
Use route chaining to determine which function will build the query
that needs to be executed. The last function is the one that actually
sends the query to the database and send the response.
Future Work:
Instead of returning a plain text response, return a HTTP 501 status,
which is currently not possible. When one attempts to send such status
the framework throws an error that the headers were already sent for
the current request.
Chaining based on the route might not be the best solution here.