Skip to content

Issue from Sentry #122

@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, we catch the ValueError exception that can be raised when converting age to an integer. If the conversion fails, we log the error and return a JSON response indicating the invalid age format.

Note: The code assumes that the request object is available and that the data variable contains the user data.

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