Skip to content

Issue from Sentry #128

@resolvd-ai

Description

@resolvd-ai

The error message "ERROR: Invalid age format provided." is being logged in the get_users() function when the code tries to convert the 'age' argument from the request into an integer. This error occurs when the 'age' argument cannot be converted into an integer, which means it's not a valid number.

Here is the code snippet that is causing the error:

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

To fix this issue, you could add a check to ensure that the 'age' argument is a digit before trying to convert it into an integer. Here is the modified code:

def get_users():
    age = request.args.get('age')
    if age:
        if age.isdigit():
            age = int(age)
        else:
            logging.error("ERROR: Invalid age format provided.")
            return jsonify({"error": "Invalid age format"}), 400

In this modified code, the isdigit() function checks if the 'age' argument is a digit. If it is, the code converts it into an integer. If it's not, the code logs an error message and returns a JSON response with an error message and a 400 status code.

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