added error handler for API request