How to use the instawow.api.ApiError function in instawow

To help you get started, we’ve selected a few instawow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github layday / instawow / instawow / api.py View on Github external
def parse_request(message: str) -> Request:
    "Parse a JSON string into a sub-``Request`` object."
    try:
        data = json_loads(message)
    except JSONDecodeError as error:
        raise ApiError.PARSE_ERROR('request is not valid JSON', str(error))
    try:
        Request(**data)
    except TypeError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       *error.args, None)
    except ValidationError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       error.json(indent=None),
                                       getattr(data, 'get', lambda _: None)('id'))

    cls = _methods.get(data['method'])
    if cls:
        try:
            return cls(**data)
        except ValidationError as error:
            raise ApiError.INVALID_PARAMS('request params are invalid',
                                          error.json(indent=None), data.get('id'))
    else:
        raise ApiError.METHOD_NOT_FOUND('request method not found',
                                        None, data.get('id'))
github layday / instawow / instawow / api.py View on Github external
def parse_request(message: str) -> Request:
    "Parse a JSON string into a sub-``Request`` object."
    try:
        data = json_loads(message)
    except JSONDecodeError as error:
        raise ApiError.PARSE_ERROR('request is not valid JSON', str(error))
    try:
        Request(**data)
    except TypeError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       *error.args, None)
    except ValidationError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       error.json(indent=None),
                                       getattr(data, 'get', lambda _: None)('id'))

    cls = _methods.get(data['method'])
    if cls:
        try:
            return cls(**data)
        except ValidationError as error:
            raise ApiError.INVALID_PARAMS('request params are invalid',
github layday / instawow / instawow / api.py View on Github external
try:
        Request(**data)
    except TypeError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       *error.args, None)
    except ValidationError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       error.json(indent=None),
                                       getattr(data, 'get', lambda _: None)('id'))

    cls = _methods.get(data['method'])
    if cls:
        try:
            return cls(**data)
        except ValidationError as error:
            raise ApiError.INVALID_PARAMS('request params are invalid',
                                          error.json(indent=None), data.get('id'))
    else:
        raise ApiError.METHOD_NOT_FOUND('request method not found',
                                        None, data.get('id'))
github layday / instawow / instawow / api.py View on Github external
def __getattr__(cls, name: str) -> Callable:
        return partial(ApiError, ErrorCodes[name])
github layday / instawow / instawow / api.py View on Github external
raise ApiError.INVALID_REQUEST('request is malformed',
                                       *error.args, None)
    except ValidationError as error:
        raise ApiError.INVALID_REQUEST('request is malformed',
                                       error.json(indent=None),
                                       getattr(data, 'get', lambda _: None)('id'))

    cls = _methods.get(data['method'])
    if cls:
        try:
            return cls(**data)
        except ValidationError as error:
            raise ApiError.INVALID_PARAMS('request params are invalid',
                                          error.json(indent=None), data.get('id'))
    else:
        raise ApiError.METHOD_NOT_FOUND('request method not found',
                                        None, data.get('id'))