Skip to content

Conversation

@KMKoushik
Copy link
Member

@KMKoushik KMKoushik commented Dec 5, 2025

Summary

  • rename the public API error class from UnsendApiError to UseSendApiError and update all usages

Linked Issues

  • None

Screenshots

  • N/A (no UI changes)

Migration Notes

  • None

Verification

  • Not run (not requested)

Codex Task


Summary by cubic

Renamed the public API error class from UnsendApiError to UseSendApiError across the codebase. This is a naming cleanup with no behavior changes.

  • Refactors
    • Updated imports, throws, and instanceof checks in public API routes, auth, middleware, and services.
    • Updated handleError to recognize UseSendApiError.

Written for commit a924a49. Summary will update automatically on new commits.

Summary by CodeRabbit

Release Notes

  • Refactor
    • Internal code updates with no user-facing changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 5, 2025

Deploying usesend with  Cloudflare Pages  Cloudflare Pages

Latest commit: a924a49
Status: ✅  Deploy successful!
Preview URL: https://8a8c8fc8.usesend.pages.dev
Branch Preview URL: https://codex-rename-unsendapierror.usesend.pages.dev

View logs

@vercel
Copy link

vercel bot commented Dec 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
unsend-marketing Error Error Dec 5, 2025 10:19pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Walkthrough

This pull request renames the exported API error class from UnsendApiError to UseSendApiError across the codebase. The rename is applied consistently across the API error definition file and all consuming files throughout the public API layer and service layer, including campaign service, contact book service, domain service, email service, team service, suppression service, idempotency service, and authentication/middleware handlers. Import statements and all throw sites are updated to use the new class name while preserving identical error codes and messages.

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.70% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'chore: rename public API error class' accurately and clearly summarizes the main change—renaming the UnsendApiError class to UseSendApiError across all files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 17 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/web/src/server/public-api/api/emails/get-email.ts (1)

6-6: UseSendApiError usage is correct; consider aligning handler name with route

The route now correctly uses UseSendApiError for the NOT_FOUND case with unchanged semantics. As a minor nit, the handler function is still named send in a get-email route file; consider renaming it (e.g., getEmail) in a future cleanup for clarity across the codebase.

Also applies to: 58-99, 91-94

apps/web/src/server/public-api/api-error.ts (1)

62-75: UseSendApiError class rename is complete and properly implemented; no backwards-compatibility alias added

The rename from the previous class name to UseSendApiError has been fully migrated throughout the codebase with 50+ consistent usages across API endpoints, schemas, services, and handlers. The handleError function correctly uses instanceof UseSendApiError at line 81, and error code mapping is preserved. However, no backwards-compatibility alias (e.g., export { UseSendApiError as UnsendApiError }) has been added. Given this class resides in the public API surface (apps/web/src/server/public-api/), confirm whether external API consumers have been notified of this breaking change or whether a compatibility alias should be exported.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3b7e4c and a924a49.

📒 Files selected for processing (17)
  • apps/web/src/server/public-api/api-error.ts (2 hunks)
  • apps/web/src/server/public-api/api-utils.ts (4 hunks)
  • apps/web/src/server/public-api/api/contacts/get-contact.ts (2 hunks)
  • apps/web/src/server/public-api/api/contacts/get-contacts.ts (1 hunks)
  • apps/web/src/server/public-api/api/domains/delete-domain.ts (3 hunks)
  • apps/web/src/server/public-api/api/domains/get-domain.ts (3 hunks)
  • apps/web/src/server/public-api/api/emails/get-email.ts (2 hunks)
  • apps/web/src/server/public-api/auth.ts (5 hunks)
  • apps/web/src/server/public-api/hono.ts (3 hunks)
  • apps/web/src/server/public-api/schemas/campaign-schema.ts (2 hunks)
  • apps/web/src/server/service/campaign-service.ts (13 hunks)
  • apps/web/src/server/service/contact-book-service.ts (2 hunks)
  • apps/web/src/server/service/domain-service.ts (6 hunks)
  • apps/web/src/server/service/email-service.ts (10 hunks)
  • apps/web/src/server/service/idempotency-service.ts (4 hunks)
  • apps/web/src/server/service/suppression-service.ts (6 hunks)
  • apps/web/src/server/service/team-service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{tsx,ts,jsx,js}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Include all required imports and ensure proper naming of key components in React/NextJS code

Files:

  • apps/web/src/server/service/suppression-service.ts
  • apps/web/src/server/service/domain-service.ts
  • apps/web/src/server/service/contact-book-service.ts
  • apps/web/src/server/service/team-service.ts
  • apps/web/src/server/public-api/api/contacts/get-contact.ts
  • apps/web/src/server/public-api/api/emails/get-email.ts
  • apps/web/src/server/public-api/hono.ts
  • apps/web/src/server/public-api/api/contacts/get-contacts.ts
  • apps/web/src/server/service/campaign-service.ts
  • apps/web/src/server/public-api/api-utils.ts
  • apps/web/src/server/public-api/api-error.ts
  • apps/web/src/server/public-api/api/domains/delete-domain.ts
  • apps/web/src/server/public-api/api/domains/get-domain.ts
  • apps/web/src/server/public-api/auth.ts
  • apps/web/src/server/service/idempotency-service.ts
  • apps/web/src/server/service/email-service.ts
  • apps/web/src/server/public-api/schemas/campaign-schema.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx}: Use TypeScript-first approach with 2-space indent and semicolons enabled by Prettier in apps/web (Next.js), apps/marketing, apps/smtp-server, and all packages
Never use dynamic imports; always import on the top level
Run ESLint via @usesend/eslint-config and ensure no warnings remain before submitting PRs

Files:

  • apps/web/src/server/service/suppression-service.ts
  • apps/web/src/server/service/domain-service.ts
  • apps/web/src/server/service/contact-book-service.ts
  • apps/web/src/server/service/team-service.ts
  • apps/web/src/server/public-api/api/contacts/get-contact.ts
  • apps/web/src/server/public-api/api/emails/get-email.ts
  • apps/web/src/server/public-api/hono.ts
  • apps/web/src/server/public-api/api/contacts/get-contacts.ts
  • apps/web/src/server/service/campaign-service.ts
  • apps/web/src/server/public-api/api-utils.ts
  • apps/web/src/server/public-api/api-error.ts
  • apps/web/src/server/public-api/api/domains/delete-domain.ts
  • apps/web/src/server/public-api/api/domains/get-domain.ts
  • apps/web/src/server/public-api/auth.ts
  • apps/web/src/server/service/idempotency-service.ts
  • apps/web/src/server/service/email-service.ts
  • apps/web/src/server/public-api/schemas/campaign-schema.ts
apps/web/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use alias ~/ for src imports in apps/web (e.g., import { x } from "~/utils/x")

Files:

  • apps/web/src/server/service/suppression-service.ts
  • apps/web/src/server/service/domain-service.ts
  • apps/web/src/server/service/contact-book-service.ts
  • apps/web/src/server/service/team-service.ts
  • apps/web/src/server/public-api/api/contacts/get-contact.ts
  • apps/web/src/server/public-api/api/emails/get-email.ts
  • apps/web/src/server/public-api/hono.ts
  • apps/web/src/server/public-api/api/contacts/get-contacts.ts
  • apps/web/src/server/service/campaign-service.ts
  • apps/web/src/server/public-api/api-utils.ts
  • apps/web/src/server/public-api/api-error.ts
  • apps/web/src/server/public-api/api/domains/delete-domain.ts
  • apps/web/src/server/public-api/api/domains/get-domain.ts
  • apps/web/src/server/public-api/auth.ts
  • apps/web/src/server/service/idempotency-service.ts
  • apps/web/src/server/service/email-service.ts
  • apps/web/src/server/public-api/schemas/campaign-schema.ts
apps/web/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/**/*.{ts,tsx}: Prefer to use TRPC for client-server communication unless explicitly asked otherwise in apps/web
Use Prisma for database access in apps/web

Files:

  • apps/web/src/server/service/suppression-service.ts
  • apps/web/src/server/service/domain-service.ts
  • apps/web/src/server/service/contact-book-service.ts
  • apps/web/src/server/service/team-service.ts
  • apps/web/src/server/public-api/api/contacts/get-contact.ts
  • apps/web/src/server/public-api/api/emails/get-email.ts
  • apps/web/src/server/public-api/hono.ts
  • apps/web/src/server/public-api/api/contacts/get-contacts.ts
  • apps/web/src/server/service/campaign-service.ts
  • apps/web/src/server/public-api/api-utils.ts
  • apps/web/src/server/public-api/api-error.ts
  • apps/web/src/server/public-api/api/domains/delete-domain.ts
  • apps/web/src/server/public-api/api/domains/get-domain.ts
  • apps/web/src/server/public-api/auth.ts
  • apps/web/src/server/service/idempotency-service.ts
  • apps/web/src/server/service/email-service.ts
  • apps/web/src/server/public-api/schemas/campaign-schema.ts
**/*.{ts,tsx,md}

📄 CodeRabbit inference engine (AGENTS.md)

Run Prettier 3 for code formatting on TypeScript, TSX, and Markdown files

Files:

  • apps/web/src/server/service/suppression-service.ts
  • apps/web/src/server/service/domain-service.ts
  • apps/web/src/server/service/contact-book-service.ts
  • apps/web/src/server/service/team-service.ts
  • apps/web/src/server/public-api/api/contacts/get-contact.ts
  • apps/web/src/server/public-api/api/emails/get-email.ts
  • apps/web/src/server/public-api/hono.ts
  • apps/web/src/server/public-api/api/contacts/get-contacts.ts
  • apps/web/src/server/service/campaign-service.ts
  • apps/web/src/server/public-api/api-utils.ts
  • apps/web/src/server/public-api/api-error.ts
  • apps/web/src/server/public-api/api/domains/delete-domain.ts
  • apps/web/src/server/public-api/api/domains/get-domain.ts
  • apps/web/src/server/public-api/auth.ts
  • apps/web/src/server/service/idempotency-service.ts
  • apps/web/src/server/service/email-service.ts
  • apps/web/src/server/public-api/schemas/campaign-schema.ts
🧬 Code graph analysis (14)
apps/web/src/server/service/suppression-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/service/domain-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/service/contact-book-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/service/team-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/api/contacts/get-contact.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/api/emails/get-email.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/hono.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/service/campaign-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/api-utils.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/api/domains/get-domain.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/auth.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/service/idempotency-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/service/email-service.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
apps/web/src/server/public-api/schemas/campaign-schema.ts (1)
apps/web/src/server/public-api/api-error.ts (1)
  • UseSendApiError (62-75)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (16)
apps/web/src/server/public-api/api/domains/delete-domain.ts (1)

4-4: UseSendApiError rename in domain delete route is consistent and correct

Import path and both throw sites now use UseSendApiError with the same FORBIDDEN/NOT_FOUND codes and messages as before; behavior is preserved.

Also applies to: 64-67, 78-81

apps/web/src/server/public-api/api-utils.ts (1)

3-3: Error helper functions now correctly use UseSendApiError

The import and all throw sites in getContactBook and email validation helpers are updated to UseSendApiError with unchanged error codes and messages, so semantics remain intact.

Also applies to: 9-12, 20-23, 33-34, 54-55

apps/web/src/server/public-api/api/domains/get-domain.ts (1)

4-4: UseSendApiError adoption in get-domain handler looks good

The handler now imports and throws UseSendApiError for both the domain restriction and service error paths, preserving existing codes (NOT_FOUND, INTERNAL_SERVER_ERROR) and behavior.

Also applies to: 38-41, 49-52

apps/web/src/server/public-api/schemas/campaign-schema.ts (1)

3-3: Campaign schema date parsing now throws UseSendApiError as expected

The import and BAD_REQUEST throw in parseScheduledAt have been switched to UseSendApiError without changing validation behavior or messaging.

Also applies to: 25-28

apps/web/src/server/service/idempotency-service.ts (1)

3-3: IdempotencyService now correctly uses UseSendApiError for validation conflicts

All idempotency-related errors (invalid key length and NOT_UNIQUE scenarios) now instantiate UseSendApiError with the same codes/messages, so external API behavior remains consistent with the previous implementation.

Also applies to: 101-105, 123-127, 143-147, 149-153

apps/web/src/server/service/domain-service.ts (1)

7-7: Domain service errors now consistently use UseSendApiError

The service correctly imports UseSendApiError and all validation/authorization/not-found branches now throw it with the same BAD_REQUEST, FORBIDDEN, and NOT_FOUND codes and messages as before, maintaining existing behavior.

Also applies to: 103-107, 114-118, 121-125, 145-148, 178-182, 219-223

apps/web/src/server/service/suppression-service.ts (1)

3-338: UseSendApiError rename in suppression service is consistent

Import and all throw sites correctly switch to UseSendApiError with unchanged codes/messages and no behavioral changes.

apps/web/src/server/public-api/api/contacts/get-contacts.ts (1)

5-5: Updated error import path looks correct

UseSendApiError is imported from "../../api-error", which correctly resolves to the shared API error module; no runtime behavior change here.

apps/web/src/server/service/team-service.ts (1)

7-170: Team invite limit error now uses UseSendApiError consistently

Import path and the createTeamInvite limit check now use UseSendApiError with the same FORBIDDEN code and message as before; behavior is preserved.

apps/web/src/server/public-api/api/contacts/get-contact.ts (1)

5-69: Contact NOT_FOUND handling correctly migrated to UseSendApiError

The import and the missing-contact branch now use UseSendApiError with the same NOT_FOUND code and message; behavior remains the same.

apps/web/src/server/service/contact-book-service.ts (1)

4-28: Contact book limit error updated to UseSendApiError without behavior change

UseSendApiError is imported from the shared API error module and used in the limit check with the same FORBIDDEN code/message; rename is consistent.

apps/web/src/server/public-api/auth.ts (1)

3-45: Auth error paths now consistently use UseSendApiError

All authorization and token-validation failures correctly throw UseSendApiError with the same codes/messages (UNAUTHORIZED / FORBIDDEN); only the error type changed.

apps/web/src/server/public-api/hono.ts (1)

9-110: Middleware and rate limiter correctly migrated to UseSendApiError

The auth middleware instanceof check and both authentication and rate-limit error throws now use UseSendApiError with the same codes/messages (INTERNAL_SERVER_ERROR, RATE_LIMITED), preserving existing semantics.

apps/web/src/server/service/email-service.ts (1)

3-754: Email service error handling fully aligned with UseSendApiError

Across checkIfValidEmail, sendEmail, updateEmail, cancelEmail, and sendBulkEmails, all previous UnsendApiError usages are now UseSendApiError with identical codes and messages, and the shared import is correct; no behavioral changes detected.

apps/web/src/server/service/campaign-service.ts (2)

21-21: LGTM: Import updated correctly.

The import statement has been correctly updated to use the renamed UseSendApiError class.


193-519: LGTM: All error throw sites updated consistently.

All public API error throw sites throughout the file have been correctly updated to use UseSendApiError. The error codes, messages, and logic remain unchanged. The distinction between public API errors (UseSendApiError) and internal service errors (Error) is appropriately maintained.

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.

2 participants