Skip to content

fix(api): suppress logging for TypeORM EntityNotFoundError in resource access guards#4432

Open
fabjanvucina wants to merge 1 commit intomainfrom
fix/resource-access-guard-log
Open

fix(api): suppress logging for TypeORM EntityNotFoundError in resource access guards#4432
fabjanvucina wants to merge 1 commit intomainfrom
fix/resource-access-guard-log

Conversation

@fabjanvucina
Copy link
Copy Markdown
Member

@fabjanvucina fabjanvucina commented Apr 10, 2026

This pull request improves error handling across several access guard classes by ensuring that EntityNotFoundError from TypeORM is treated as a "not found" condition, similar to NestJS's NotFoundException. This prevents unnecessary logging of expected errors and provides more consistent error responses when resources are missing.

Error Handling Improvements:

  • All affected guard classes now import EntityNotFoundError from TypeORM and check for it alongside NotFoundException when handling errors, preventing unnecessary error logging for missing entities. [1] [2] [3] [4] [5] [6] [7] [8]
  • The error handling logic in the following guards was updated to include EntityNotFoundError:
    • DockerRegistryAccessGuard
    • RegionAccessGuard
    • JobAccessGuard
    • RunnerAccessGuard
    • SandboxAccessGuard
    • SnapshotAccessGuard
    • SnapshotReadAccessGuard
    • VolumeAccessGuard

These changes ensure that missing resources are handled gracefully and consistently across the API.


Summary by cubic

Treat typeorm’s EntityNotFoundError as “not found” in resource access guards to stop logging expected errors and return consistent 404s. Applies to Docker registry, region, job, runner, sandbox, snapshot (read + write), and volume guards.

  • Bug Fixes
    • Check EntityNotFoundError from typeorm alongside NotFoundException, suppress logging in these cases, and rethrow a NotFoundException.

Written for commit 9be8fca. Summary will update on new commits.

…e access guards

Signed-off-by: fabjanvucina <fabjanvucina@gmail.com>
Copilot AI review requested due to automatic review settings April 10, 2026 14:11
Copy link
Copy Markdown

@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 8 files

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 10, 2026

View your CI Pipeline Execution ↗ for commit 9be8fca

Command Status Duration Result
nx run-many --target=test --all --nxBail=true ✅ Succeeded 1m 15s View ↗
nx run-many --target=build --all --parallel=4 -... ✅ Succeeded 17s View ↗
nx run-many --target=docs --all ✅ Succeeded <1s View ↗
nx run-many --target=format --all --parallel=4 ✅ Succeeded 6s View ↗
nx run api:lint ✅ Succeeded <1s View ↗
nx run-many --target=generate:api-client --all ... ✅ Succeeded 15s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-10 14:17:05 UTC

Copy link
Copy Markdown

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 updates multiple API resource access guards to treat TypeORM EntityNotFoundError as an expected “not found” condition (like NestJS NotFoundException), avoiding unnecessary error logs and returning consistent 404 responses for missing resources.

Changes:

  • Import EntityNotFoundError in affected guards.
  • Update guard catch blocks to skip logger.error when the caught error is NotFoundException or EntityNotFoundError.
  • Keep consistent NotFoundException responses for missing resources across guards.

Reviewed changes

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

Show a summary per file
File Description
apps/api/src/docker-registry/guards/docker-registry-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/region/guards/region-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/sandbox/guards/job-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/sandbox/guards/runner-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/sandbox/guards/sandbox-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/sandbox/guards/snapshot-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/sandbox/guards/snapshot-read-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.
apps/api/src/sandbox/guards/volume-access.guard.ts Suppress logging for EntityNotFoundError and normalize to NotFoundException.

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

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.

2 participants