Standardized exception handling for JSON or XML requests