Improved error reporting on API handlers