【发布时间】:2021-07-19 13:18:29
【问题描述】:
如果我的访问令牌过期,我的 Locust 任务可能会以 401 告终。在这种情况下,我将更新它,然后重试该任务。这一切都很完美(基于this):
@task
def list_claims(self):
with self.client.get("/api/1.0/claim/", name="LIST claims", headers=self.headers, catch_response=True) as response:
if response.status_code == 401:
logging.info("401 - Need to fetch a new access token!") # usually happens when the access tokens expires after an hour
self.aad_b2c_auth()
raise RescheduleTaskImmediately() # re-run this task with the newly refreshed token
问题是这似乎吸收了所有其他状态代码,所以任务永远不会显示为失败,即使它,例如,返回 503 等。我认为这是因为 catch_response=True?!所以理想情况下,我只想对 401 进行特殊处理,并将其余部分留给默认处理程序(2xx = 成功,4xx/5xx = 失败)。有没有内置的方法来实现这一点?
【问题讨论】: