def METHOD_NAME(exc) -> typing.Optional[dict]:
    if (
        hasattr(exc, "detail")
        and isinstance(exc.detail, list)
        and len(exc.detail) > 0
        and isinstance(exc.detail[0], Message)
    ):
        return dict(
            messages=lib.to_dict(
                [
                    dict(
                        code=msg.code,
                        message=msg.message,
                        details=msg.details,
                        carrier_id=msg.carrier_id,
                        carrier_name=msg.carrier_name,
                    )
                    for msg in typing.cast(typing.List[Message], exc.detail)
                ]
            )
        )
    return None