Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception handling for 'create mind' #126

Merged
merged 1 commit into from
Jun 25, 2024
Merged

Conversation

StpMax
Copy link
Contributor

@StpMax StpMax commented Jun 25, 2024

e.response.json() fail if response does not contain json. 'Parsing error' confusing in this case, so added better error message.

@StpMax StpMax requested a review from tmichaeldb June 25, 2024 12:12
Copy link

Coverage

Coverage Report
FileStmtsMissCoverMissing
mindsdb_sdk
   agents.py1974975%23, 82, 90, 98, 106, 114, 124, 127, 131, 133, 135, 137, 139, 200–212, 224, 233–237, 244–245, 282, 294–295, 336, 353–355, 371, 376–378, 409–410, 430–432, 436–440
   databases.py45296%109, 137
   handlers.py39197%77
   jobs.py97793%41, 53, 81, 85, 147–150
   knowledge_bases.py1261588%58–61, 151, 155–162, 167–171, 250–253, 322, 339
   ml_engines.py42393%94, 126, 128
   models.py2111991%109, 140–141, 222, 231, 233, 303, 339, 348, 372, 403, 497, 505, 524, 540, 548, 573, 577, 590
   projects.py64198%168
   query.py13192%14
   skills.py53394%43, 45, 49
   tables.py1301588%140–142, 145, 165, 192, 203–204, 209, 224, 227, 321, 342–347, 356, 376
   views.py37295%105, 138
mindsdb_sdk/connectors
   rest_api.py2083384%16–26, 32–33, 48, 51–52, 72–74, 95, 98, 105–108, 141–149, 196, 210–211
mindsdb_sdk/utils
   mind.py25250%1–69
   openai.py853065%37–40, 83–85, 107, 148–158, 215–216, 234–240, 258–276
   table_schema.py21210%1–54
TOTAL148122785% 

Tests Skipped Failures Errors Time
23 0 💤 0 ❌ 0 🔥 9.115s ⏱️

Copy link
Contributor

@ea-rus ea-rus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Maybe better would be:

    try:
        response = requests.post(url, json=payload, headers=headers)
        if response.status_code  != 200:
        try:
            error_message = response.json()
        except JsonDecodeError:
            error_message = response.text
        logger.error(f"Failed to create mind: {error_message}")
        raise e
    except Exception as e:
        logger.error(f"Failed to create mind: {e}")
        raise e

@StpMax StpMax merged commit d1fbab7 into staging Jun 25, 2024
5 checks passed
@ea-rus ea-rus mentioned this pull request Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: merged
Development

Successfully merging this pull request may close these issues.

2 participants