aphiria / api

[READ-ONLY] A library to build APIs using Aphiria
https://www.aphiria.com
MIT License
3 stars 3 forks source link

Exception handling does not (easily) support returning custom error views for non-API endpoints #9

Closed davidbyoung closed 5 years ago

davidbyoung commented 5 years ago

Our exception handlers are especially configured to create responses for API calls. However, this makes it difficult (impossible?) to reuse the API library for returning server-side rendered views.

Possible options to explore:

davidbyoung commented 5 years ago

Thoughts

I can separate out registering a global exception handler from a handler that returns an HTTP response. The former would use set_error_handler() and the latter would require adding the following classes:

davidbyoung commented 5 years ago

I've rewritten exception handling to have two distinct components:

I still need to settle on whether or not I want to move the registerFactory() and registerManyFactories() methods from ExceptionResponseFactoryRegistry to ExceptionResponseFactory (perhaps they could be methods only available on the concrete implementation of IExceptionResponseFactory). It feels a little overkill to have the factory compose the registry. I'll have to mull this over.

davidbyoung commented 5 years ago

This also brings up the question of whether or not exception handling should go in its own library, dependent on Net and Middleware. It's not inherently tied up with API anymore.