Modify error handling of api