我目前有一个函数可以根据给出的错误代码(int
)返回错误消息。问题是我拥有Try
/ Except
内的所有内容,而且一切都在运行......我放了一些print
,所以它们会被打印到控制台,所以我可以看到这个函数停止了...但它一直到最后,消息最终成为函数的最终定义..
代码:
# function for processing declined card errors
def declined_card(code):
"""
Take in the processor_response_code and return the proper error.
- processor_response_code supplied by Braintree on declined card
"""
try:
# codes falling outside of the dictionary
print "testing 1: " + code
if 2092 <= code <= 2999:
message = "Your payment method has been declined. Please contact your bank " \
"for more information."
elif code >= 3000:
print "testing 2: " + code
message = "There was an issue with the back-end processing network. Please try " \
"your transaction again. If this issue persists, please contact " \
"us using the help page."
# codes within the dictionary
print "testing 3: " + code
if error_codes[code]:
message = error_codes[code]
return message
except KeyError:
print "testing 4: " + code
message = "There has been an error with payment processessing. Please contact us " \
"using the help page for more information."
return message