[Backend] Sanitize Prisma database errors in API responses to prevent schema disclosure
Overview
When unexpected database errors occur (e.g. unique constraint violations, foreign key mismatches), Prisma's raw error strings can leak table names and column layouts to the client.
Problem
- Internal database details exposed in HTTP response bodies aid attackers in reconnaissance.
Proposed Changes
- Enhance
backend/src/lib/api-error.tsand error handler middleware. - Intercept Prisma errors (
PrismaClientKnownRequestError) and map to generic, safe error codes (e.g.DUPLICATE_ENTRY,RESOURCE_NOT_FOUND). - Log full stack trace internally via Winston, but send only safe messages to client.
Acceptance Criteria
- [ ] Raw SQL and table names never appear in 4xx/5xx response bodies.
- [ ] Full error context preserved in internal logs for debugging.
- [ ] Unit tests verify masked error responses.
@aduagba4133 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
I am a detail-oriented and reliable individual with strong skills in research, data entry, online tasks, and following instructions. I am committed to delivering accurate and high-quality work within deadlines and am available to start tasks immediately.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @aduagba4133 to this issue.
@Oluwasuyi-Oluwatimilehin-Daniel has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
Hello @maintainer, I’d like to work on this issue. I have experience handling similar tasks and can start immediately. And I will deliver at the shortest possible time.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Oluwasuyi-Oluwatimilehin-Daniel to this issue.
Congratulations, @Oluwasuyi-Oluwatimilehin-Daniel! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.
🧑💻 @Oluwasuyi-Oluwatimilehin-Daniel: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
This issue has been marked as completed by a Drips Wave moderator for @timiturn3r as part of the Stellar Wave Program's 9th Wave 🥳
Moderator's reason: [Auto-assessed] The PR was successfully merged by maintainers (mergedAt: 2026-10-10T10:17:55Z), fulfilling the acceptance criteria of sanitizing Prisma errors and adding comprehensive unit tests.
😎 @timiturn3r: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.
ℹ️ Note: This issue was marked complete via moderation. Points were issued even though the GitHub issue remains open.