"An error occurred." Four words I've seen thousands of times. Also completely useless. What error? Where? Why? What do I do now?
Good error messages are a feature, not an afterthought. They save time, reduce support tickets, and make users feel like they're dealing with a professional product.
The Anatomy of a Good Error Message
Tell the user what happened. Not "An error occurred" but "The file 'report.pdf' exceeds the maximum size of 10MB."
Tell them why it happened, if helpful. "Connection timeout after 30 seconds. The server may be busy."
Tell them what to do about it. "Try again in a few moments, or contact support if the problem persists."
HTTP Status Pages
404 pages should be helpful. A giant "404 NOT FOUND" with no context is lazy. Include a search box, links to popular pages, maybe a joke. The user is already frustrated—don't make it worse.
500 errors should apologize, suggest retrying, and offer a way to report the issue. Never show stack traces in production.
Log Details, Don't Show Them
When something goes wrong, log everything—the full stack trace, request headers, user ID, whatever you need to debug. But show users only what they need to see. Technical details help attackers and confuse users.