Refactor API error reporting.