Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

JSON Errors

Remember the ultimate goal of this work is to have a dumb webserver make a REST API by calling functions that always start with SELECT mime, JS FROM, like this:

SELECT mime, js FROM get_person(123);
SELECT mime, js FROM update_person(123, '{"name":"Dude"}');
SELECT mime, js FROM client_delete_project(7, 95);

The webserver knows it will always get back a MIME type and JSON hash, so it can just pass those directly into its HTTP response. No special intelligence needed by the webserver.

So instead of PostgreSQL raising exceptions, I want to catch all exceptions, and return application/api-problem+json, like this.

status: many questions

How to structure the error-catching & response-forming function?

  • Every function repeats the entire process of catching errors and turning them into JSON responses?
  • Only one function performs a query and catches the error, and every other function passes its query through this one, like a proxy?
  • One function takes an error and creates the JSON response. Every other function calls it in its EXCEPTION block?
  • Some kind of higher-level “catch all errors and handle them like this” config for PostgreSQL?
  • Use m4 template to generate repeated code, instead of trying to function/abstract it away.