1 hour ago · Tech · hide · 0 comments

There There, the helpdesk we're building at Spatie, is a project of learned habits. Twenty-some years of writing Laravel apps has taught us which patterns pay off and which ones quietly rot. One that keeps earning its keep is a custom exception class for every domain error. This is a small pattern, but it's one of those things that makes a codebase nicer to live in. There There is in private beta right now, and you can apply for early access at there-there.app. Exceptions that explain themselves The conventional answer for a domain error is something like throw new InvalidArgumentException("Only notes can be deleted"). It works, the test passes, the user sees a 500 page. But then three months later you try to catch just this specific error and you can't, because InvalidArgumentException is thrown from a dozen other places. Our pattern is one class per domain error, with a static factory method per reason. Here's the one that fires when someone tries to delete a message that isn't a…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.