Add error handler to API