+## Formatting error messages
+
+Any exception thrown during processing of a request is given to
+a special error formatting function. It takes the requested content type,
+the status code and the error message. It should return the error message
+in a form appropriate for the given content type.
+
+You can overwrite the default formatting function with the decorator
+`error_format_func`:
+
+``` python
+import nominatim_api.server.content_types as ct
+
+@dispatch.error_format_func
+def _format_error(content_type: str, msg: str, status: int) -> str:
+ if content_type == ct.CONTENT_XML:
+ return f"""<?xml version="1.0" encoding="UTF-8" ?>
+ <message>{msg}</message>
+ """
+ if content_type == ct.CONTENT_JSON:
+ return f'"{msg}"'
+
+ return f"ERROR: {msg}"
+```
+
+
+## Debugging custom formatters
+
+The easiest way to try out your custom formatter is by using the Nominatim
+CLI commands. Custom formats can be chosen with the `--format` parameter:
+
+```
+me@machine:planet-project$ nominatim status --format chatty
+2024-08-16 19:54:00: Using project directory: /home/nominatim/planet-project
+Good news! The server is running just fine.
+me@machine:planet-project$
+```
+
+They will also emit full error messages when there is a problem with the
+code you need to debug.
+
+!!! danger
+ In some cases, when you make an error with your import statement, the
+ CLI will not give you an error but instead tell you, that the API
+ commands are no longer available:
+
+ me@machine: nominatim status
+ usage: nominatim [-h] [--version] {import,freeze,replication,special-phrases,add-data,index,refresh,admin} ...
+ nominatim: error: argument subcommand: invalid choice: 'status'
+
+ This happens because the CLI tool is meant to still work when the
+ nominatim-api package is not installed. Import errors involving
+ `nominatim_api` are interpreted as "package not installed".
+
+ Use the help command to find out which is the offending import that
+ could not be found:
+
+ me@machine: nominatim -h
+ ... [other help text] ...
+ Nominatim API package not found (was looking for module: nominatim_api.xxx).
+