Skip to content

No error handling for null google books data #45

@jose-marquez89

Description

@jose-marquez89

When a google books api call returns with no books, the 'items' key will be missing from the json response. This causes a KeyError in recommender.py. Error handling here is necessary:

 def db_insert(self, isbn=None):
        api = GBWrapper()
        if isbn is not None:
            google_books_response = api.search(isbn)
        else:
            google_books_response = api.search(self.googleId)

        # INSERTS GB_QUERY INTO DATABASE
        logging.debug("GETTING API DATA...")
        # add error handling for the line below:
        api_data = get_value(google_books_response['items'][0])
        if isbn is not None:
            gid = api_data[0]
            details = retrieve_details(google_books_response)
        else:
            gid = None
            details = None
        # execute_queries(api_data, self.conn, self.cursor)
        execute_queries(api_data, self.conn)
        return gid, details

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions