# Code generated by op-codegen - DO NO EDIT MANUALLY

import json


class DesktopSessionExpiredException(Exception):
    def __init__(self, message):
        self.message = message
        super().__init__(self.message)


class RateLimitExceededException(Exception):
    def __init__(self, message):
        self.message = message
        super().__init__(self.message)


def raise_typed_exception(e: Exception):
    try:
        typed_error = json.loads(e.msg)
    except Exception:
        raise e

    error_name = typed_error.get("name")
    message = typed_error.get("message")

    if error_name == "DesktopSessionExpired":
        raise DesktopSessionExpiredException(message)
    elif error_name == "RateLimitExceeded":
        raise RateLimitExceededException(message)
    elif message is not None:
        raise Exception(message)
    else:
        raise e
