I have added a new configurable variable to config/app.php that can be set in the .env file but this one must be in the form of a valid regex pattern (it is used by a middleware layer in my app).
It is possible that a future developer might not realise it has to be a proper regex pattern and just supplies a string which will cause them all sorts of headaches (this "future developer" may actually be me in 2 years time). In which case I would like to throw a nice error message explaining that they need to fix this variable. I presume the middleware that uses it is the best place to do the validation but my question is how should I throw the error?
- An exception? If so, which one's appropriate?
- Set a 4xx status code in the header, dump a plain text message and exit? (afterall this variable is only going to be changing at the time of installation so interrupting service won't matter)
- Just let the default PHP error happen when the invalid pattern is fed into a
preg_*
function - Some other built-in Laravel 5 feature that I don't know about?
I'd love to know people's opinions.