Blog

Brad Wood

December 26, 2016

Spread the word


Share your thoughts

This is our final installment of the 12 Tips of (CommandBox) Christmas and we hope you've learned some new tricks.  In this last segment, we'll cover setting up custom error pages for your CommandBox-based web servers.  This applies to all CF engines that you start and can help you add a bit of polish to a CommandBox-powered site you want to make public. 

Custom Error Pages

CommandBox's server started as a development tool, but has now grown to a fully-functional and performant web server that can handle most any site.  You can customize the error page that CommandBox servers return when a missing file is requested. You can have a setting for each status code including a default error page to be used if no other setting applies.


Create an errorPages object inside the web object in your server.json where each key is the status code integer or the word default and the value is a relative (to the web root) path to be loaded for that status code.
This is what you server.json might look like:

{
  "web" : {
    "errorPages" : {
      "404" : "/path/to/404.html",
      "500" : "/path/to/500.html",
      "default" : "/path/to/default.html"
    }
  }
}

You can set error pages via the server set command like this:

server set web.aliases.404=/missing.htm

Accessing error variables

If your error page points to a CFM file, you can get access to the original path being accessed for 404s and the error that was thrown for 500s. This requires that your error handler page is CFML.  To see all the request headers that are available, use the following snippet of code:

req = getPageContext().getRequest();
names = req.getAttributeNames();
while( names.hasMoreElements() ) {
    name = names.nextElement();
    writeDump( name & ' = ' & req.getAttribute( name ) );
}

An example of getting the original missing path in a 404 would look like this:

var originalPath = getPageContext().getRequest().getAttribute( "javax.servlet.error.request_uri" );


 

Add Your Comment

Recent Entries

πŸš€ ColdBox CLI 8.11: The Era of AI Skills Comes to Every ColdBox & BoxLang App

πŸš€ ColdBox CLI 8.11: The Era of AI Skills Comes to Every ColdBox & BoxLang App

ColdBox CLI 8.11 is here, and it's one of the most significant releases we've shipped for AI-assisted development. This release wires the CLI directly into our brand new public skills directory at skills.boxlang.io, brings our AI tooling in line with industry-wide agent conventions, and introduces a wave of quality-of-life improvements that make AI integration feel less like setup and more like infrastructure.

Luis Majano
Luis Majano
April 30, 2026
πŸ›°οΈ Introducing cbMCP β€” Your ColdBox App, Live to Every AI Agent

πŸ›°οΈ Introducing cbMCP β€” Your ColdBox App, Live to Every AI Agent

Today we're releasing cbMCP, the official ColdBox MCP Server β€” a BoxLang-only module that turns your running ColdBox application into a fully-compliant Model Context Protocol (MCP) server. Plug in any MCP-capable AI client β€” Claude Desktop, VS Code Copilot, Cursor, Codex, Gemini CLI, OpenCode β€” and your AI assistant gets live, read-only introspection across the entire ColdBox platform: routing, handlers, modules, WireBox, CacheBox, LogBox, schedulers, interceptors, and async executors. 🎯

Luis Majano
Luis Majano
April 30, 2026