Adding error handling for API error messages