Skip to content

Issue from Sentry #116

@resolvd-ai

Description

@resolvd-ai

Based on the provided alert, the error "ERROR: Invalid age format provided" is being caused by the code in the get_users() function. Specifically, the error occurs when trying to convert the age parameter to an integer using the int() function.

To fix this issue, you can modify the code as follows:

def get_users():
    age = request.args.get('age')
    if age:
        try:
            age = int(age)  # This can raise a ValueError
        except ValueError:
            logging.error("ERROR: Invalid age format provided.")
            return jsonify({"error": "Invalid age format"}), 400

    results = []
    for entry in data:
        if 'age' in entry:
            # Avoiding TypeError by ensuring both are integers for comparison
            if age and int(entry["age"]) == age:
                results.append(entry)
        elif not age:
            results.append(entry)

    return jsonify(results)

In this updated code, the age parameter is first checked if it exists. If it does, it is attempted to be converted to an integer using int(). If a ValueError is raised during the conversion, the error is logged and a JSON response with an error message is returned with a status code of 400.

This modification ensures that only valid integer values for the age parameter are processed, preventing the "Invalid age format" error from occurring.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions