Add error handler for API