Add error handling for non-JSON responses