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

fix: return protocol error messages for user restrictions #111

Merged
merged 3 commits into from
Sep 11, 2024

Conversation

codeincontext
Copy link
Collaborator

@codeincontext codeincontext commented Sep 10, 2024

Description

Our streaming chat protocol allows us to send predefined error and action messages when a user is banned, rate limited, etc. With recent refactors we've lost some of that functionality

Changes:

  • Replace failureMessage pattern in chat handler, and throw specific error instances instead
    • Extract error handling code to new file
  • Catch known error instances in chat handler, and respond with the appropriate protocol message
  • Remove redundant wrappers around user lookup function
  • Remove shouldPerformUserLookup, handleUserLookup, mockUserId functionality as it was only used to support tests

How to test

Rate limiting

  1. Set a low RATELIMIT_GENERATIONS_PER_24H in doppler
  2. Rebuild the deployment
  3. Go to https://oak-ai-lesson-assistant-6qy6b39gj.vercel-preview.thenational.academy
  4. Sign in with an account in the pattern myname**+rate-limit-me**@thenational.academy
  5. Write some messages
  6. You should see a rate limit message

Account locking

  1. Go to https://oak-ai-lesson-assistant-eh6lpshzj.vercel-preview.thenational.academy
  2. Create 3 lessons with mod:tox as the text
  3. You should see an "account locked page"

Screenshots

CleanShot 2024-09-10 at 21 11 03@2x
CleanShot 2024-09-10 at 21 01 20@2x

Copy link

vercel bot commented Sep 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
oak-ai-lesson-assistant ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 7:21pm

Copy link

github-actions bot commented Sep 10, 2024

Playwright e2e tests

Job summary

Download report

To view traces locally, unzip the report and run:

npx playwright show-report ~/Downloads/playwright-report

@codeincontext codeincontext force-pushed the fix/rate-limit-response branch from d8c459c to a717c6d Compare September 10, 2024 19:15
@codeincontext codeincontext marked this pull request as ready for review September 10, 2024 19:16
Copy link

}

throw e;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is all much neater

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah! Much nicer to have it in one place

Copy link
Contributor

@stefl stefl left a comment

Choose a reason for hiding this comment

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

Looks good - I've not run this to verify, but this all seems much neater

@codeincontext codeincontext merged commit 741c935 into main Sep 11, 2024
15 checks passed
@codeincontext codeincontext deleted the fix/rate-limit-response branch September 11, 2024 08:07
@oak-machine-user
Copy link
Collaborator

🎉 This PR is included in version 1.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants