def METHOD_NAME(response):
    if response.status_code in [500, 502]:
        raise CaptchaServiceUnavailable(
            f'anticaptcha: Server Side Error {response.status_code}'
        )
    payload = response.json()
    if payload['errorId'] >= 1:
        if 'errorDescription' in payload:
            raise CaptchaAPIError(
                payload['errorDescription']
            )
        else:
            raise CaptchaAPIError(payload['errorCode'])