Skip to content

Instantly share code, notes, and snippets.

@adhorn
Created July 11, 2019 12:13
Show Gist options
  • Save adhorn/8ac815eb546d79a0ab7717ef8278ac77 to your computer and use it in GitHub Desktop.
Save adhorn/8ac815eb546d79a0ab7717ef8278ac77 to your computer and use it in GitHub Desktop.
@corrupt_statuscode decorator
def corrupt_statuscode(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
error_code, rate = get_config('error_code')
if not error_code:
return result
print("Error from config {0} at a rate of {1}".format(error_code, rate))
# add injection approx rate% of the time
if random.random() <= rate:
print("corrupting now")
result['statusCode'] = error_code
return result
else:
return result
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment