How to use the omas.exceptions.UnknownMEIReadException function in omas

To help you get started, we’ve selected a few omas 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 umd-mith / ema / Omas / api.py View on Github external
def get_external_mei(meiaddr):
    r = requests.get(unquote(meiaddr), timeout=15)
    # Exeunt stage left if something went wrong.
    if r.status_code != requests.codes.ok:
        if r.status_code == 404:
            msg = "The MEI File could not be found"
            raise CannotAccessRemoteMEIException(msg)
        else:
            msg = "An unknown error ocurred. Status code: {0}".format(
                r.status_code)
            raise UnknownMEIReadException(msg)

    return r.content
github umd-mith / ema / Omas / api.py View on Github external
def information(meipath):
    try:
        mei_as_text = get_external_mei(meipath)
    except CannotAccessRemoteMEIException as ex:
        return {"message": ex.message}, status.HTTP_400_BAD_REQUEST
    except UnknownMEIReadException as ex:
        return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR

    try:
        parsed_mei = meiinfo.read_MEI(mei_as_text).getMeiDocument()
    except CannotReadMEIException as ex:
        # return a 500 server error with the exception message
        return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR

    # it's possible that this will raise some exceptions too, so break it out.
    try:
        mus_doc_info = meiinfo.MusDocInfo(parsed_mei).get()
    except BadApiRequest as ex:
        return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR

    return mus_doc_info