ReedyBear's Blog

Idea: ErrorHandling Library for PHP

In my project Liaison, I throw an exception that says:

No routes were found for this request to /

This exception text (not the /) is hardcoded into Liaison.

I'd like to take it out of there & put it into a library-configuration file.

I previously made a library 'Resources' with the shorthand R() to get settings stored in a file.

But I used it wrong. I used it for settings - like different text on a website.

But that was wrong.

I want that library for code, essentially. Code as json strings. Json strings as code? Idk whateva.

So I might use R() in Liaison as a way to load up error messages.

I'm concerned about putting too much in-memory on regular web-requests if I need to use R() to lookup resources then. (doesn't matter with exceptions being thrown probably, but it does matter if it's just like, a css class name on an html element that's part of the site's layout.)

So I considered that the php package could essentially be compiled, and the R() calls could be replaced with their raw value.

I could build a Code Scrawl extension to do this, or possibly finish my PHP build tool and use that.

Idunner. I like to say "I had an idea; now it's yours" ... which, sure. But this is so specific to me that I'm not sure it counts. I guess the underlying idea might be interesting.

Oh!

The rest of the error handling idea. errors.json: (or something)

{
    "NoRoutesFound": {
        "ExceptionMessage": "No routes were found for the request to %s",
        "UserMessage": "Page not found.",
        "HelpDocs": "https://liaison.reedybear.com/error/NoRoutesFound" 
    }
}

I'd want to generate the HelpDocs link.

Then the HelpDocs would be manually written, I think, on the web. It would not be part of errors.json. This would make it more dynamic. This would probably tell you to add routes & suggest addRoute(), public dir, or to read more documentation on Routing.

#code #idea