Don't report a cancelled task as a refused refund - #44
Open
zlexdev wants to merge 2 commits into
Open
Conversation
`Refund.parse_result` caught everything:
except:
raise RefundError(order_id=..., message=f'Unable to refund order {...}')
`CancelledError` and `KeyboardInterrupt` derive from `BaseException`, so a task
cancelled mid-refund surfaces as "unable to refund" for an order whose request
may already be in flight. The two states a caller must tell apart -- refused and
unknown -- become one.
The message drops the reason as well: no `from`, and nothing of the decode
error, so an HTML login page and a truncated body are the same sentence.
Now:
except json.JSONDecodeError as exc:
methods_logger.debug('refund %s: response is not JSON: %r', ...)
raise RefundError(..., message=f'Unable to refund order {...}: {exc}') from exc
`methods_logger` is new and follows the existing one-per-subsystem shape in
`loggers.py`; `methods` had none. The raw body goes to DEBUG only -- it is what
says why parsing failed, and it is also a full HTML page when the answer was a
login form.
`tests/test_refund.py`: four tests, two of which fail on the parent commit --
the chained cause and the cancellation.
A refused refund answered with a login page put a whole HTML document in the log, once per failure. The head identifies it; the length is printed beside it so nothing is hidden without saying so.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refund.parse_resultcatches everything —funpaybotengine/methods/refund.py:42-49:CancelledErrorandKeyboardInterruptderive fromBaseException, so:The order may already be refunded. Refused and unknown arrive as the same
exception, and a caller retrying on
RefundErrorretries a refund that went through.The reason is dropped too — no
from, nothing of the decode error — so an HTML loginpage and a truncated body produce one identical sentence.
What changes
json.JSONDecodeErroris caught specifically, its text goes into the message, and thecause is chained.
loggers.pygainsmethods_logger, following the one-per-subsystemshape already there (
session,router,dispatcher,runner);methodshad none.The raw body goes to DEBUG only, capped at 500 characters with the full length printed
beside it — when the answer is a login page it is a whole HTML document, and every failed
refund would put one in the log.
Tests
tests/test_refund.py, four tests. On the parent commit:ruffandmypyclean on the touched files. Pre-existing findings elsewhere are leftalone.