Coverage for functions \ flipdare \ error \ stripe_msg_format.py: 0%
37 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
12from __future__ import annotations
14from flipdare.error.formatted_stripe_error import FormattedStripeError
15from flipdare.error.message_format import BaseMsgFormat, MessageContext, MessageSection
16from flipdare.generated.shared.app_payment_error_code import AppPaymentErrorCode
17from flipdare.generated.shared.backend.system_log_type import SystemLogType
18from flipdare.payments.payment_types import KnownStripeErrorType
20__all__ = ["StripeMsgFormat"]
23class StripeMsgFormat(BaseMsgFormat):
24 __slots__ = ("_error", "_error_code")
26 _error_code: AppPaymentErrorCode
27 _error: KnownStripeErrorType
29 def __init__(self, endpoint: str, message: str, error: KnownStripeErrorType) -> None:
31 formatted = FormattedStripeError.from_exception(error)
33 self._error_code = formatted.error_code
34 self._error = error
36 ctx = MessageContext(log_type=SystemLogType.ERROR)
37 # main
38 ctx.add("Endpoint", endpoint)
39 ctx.add("App Error Code", formatted.error_code)
40 ctx.add("Stripe Error Code", formatted.stripe_error_code or "N/A")
41 ctx.add("Stripe Error Type", formatted.stripe_error_type or "N/A")
42 ctx.add("Is Retryable", formatted.is_retryable)
44 # config
45 ctx.add("HTTP Status", formatted.http_code or "N/A")
46 ctx.add("Request ID", formatted.request_id or "N/A")
47 ctx.add("Decline Code", formatted.decline_code or "N/A")
48 ctx.add("Charge ID", formatted.charge_id or "N/A")
49 ctx.add("Param", formatted.param or "N/A")
51 # actual errors.
52 section = MessageSection(log_type=SystemLogType.ERROR)
53 section.add("Raw Error", str(formatted.raw_error or "N/A"))
54 section.add("Error Message", formatted.message or "N/A")
55 section.add("User Message", formatted.user_message or "N/A")
57 super().__init__(
58 log_type=SystemLogType.ERROR,
59 source=endpoint,
60 user_error_code=formatted.error_code,
61 message=message,
62 context=ctx,
63 section=section,
64 )
66 @property
67 def error(self) -> KnownStripeErrorType:
68 return self._error
70 @property
71 def error_code(self) -> AppPaymentErrorCode:
72 return self._error_code