Better handling of API exceptions