Skip to content

Improve error handling for user lookup by email#1766

Merged
cezudas merged 1 commit intomainfrom
cezudas/OPS-3009-getUserbyEmail-refactor
Dec 12, 2025
Merged

Improve error handling for user lookup by email#1766
cezudas merged 1 commit intomainfrom
cezudas/OPS-3009-getUserbyEmail-refactor

Conversation

@cezudas
Copy link
Copy Markdown
Contributor

@cezudas cezudas commented Dec 12, 2025

Part of OPS-3009.

Copilot AI review requested due to automatic review settings December 12, 2025 07:19
@linear
Copy link
Copy Markdown

linear Bot commented Dec 12, 2025

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 12, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cezudas/OPS-3009-getUserbyEmail-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@cezudas cezudas marked this pull request as draft December 12, 2025 07:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the user lookup function to improve error handling consistency. The changes rename getUserByEmailOrFail to getUserByEmailOrThrow and replace the repository's built-in error handling with explicit error checking and custom error throwing.

Key changes:

  • Renamed function from getUserByEmailOrFail to getUserByEmailOrThrow for clearer semantics
  • Replaced findOneByOrFail with explicit null checking and custom ApplicationError throwing
  • Simplified function signature to accept email string directly instead of object parameter

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/server/api/src/app/user/user-service.ts Refactored getUserByEmail function with explicit error handling and renamed to getUserByEmailOrThrow
packages/server/api/src/app/openops-tables/auth-admin-tables.ts Updated function call to use new getUserByEmailOrThrow with simplified parameter
packages/server/api/src/app/authentication/new-user/organization-assignment.ts Updated function call to use new getUserByEmailOrThrow with simplified parameter
packages/server/api/test/unit/openops-tables/auth-admin-tables.test.ts Updated mock function name to match the renamed getUserByEmailOrThrow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sonarqubecloud
Copy link
Copy Markdown


async getUserByEmailOrFail({ email }: { email: string }): Promise<User> {
return userRepo().findOneByOrFail({ email });
async getUserByEmailOrThrow(email: string): Promise<User> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one will result in status 404 in global exception handlers, which is preferable to status 500.

@cezudas cezudas marked this pull request as ready for review December 12, 2025 11:24
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@cezudas cezudas merged commit 0095a14 into main Dec 12, 2025
24 checks passed
@cezudas cezudas deleted the cezudas/OPS-3009-getUserbyEmail-refactor branch December 12, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants