send errors as JSON responses