bcgov / bcgov/SIMS

BUG: Audit API JWT failure is logged as an unhandled exception

Open
#6,575 0 comments 0 reactions 1 assignee Claimed by @uhelm View on GitHub
Dev & Architecture
Dominant language
TypeScript
Stars
29
Forks
15
PR merge metrics
No merged PRs in 30d

Description

**Describe the Bug**

A `POST /api/audit` request fails JWT authentication with a 401 response and is emitted by `AppAllExceptionsFilter` as an unhandled error.

**Expected Behaviour**

- Authentication failures are handled as expected client responses and do not generate misleading unhandled-exception error logs.
- Ensure the web application will no longer call the endpoint if the token is not present or no longer valid; for instance, ensure it is not expired, which is a possible assumption that may be causing most of the issues.
- For this endpoint, if the token is not validated, do not generate an unhandled exception that would lead to the `AppAllExceptionsFilter` log.

**Actual Behaviour**

The API returns 401 and records `UnauthorizedException: Unauthorized` as an unhandled exception.

**Log**

```text
[Nest] 18 - 09/04/2026, 3:40:17 PM LOG [AccessLoggerMiddleware] Request - POST /api/audit From [redacted] | User GUID: [redacted] | User Agent: Chrome 116 on macOS
[Nest] 18 - 09/04/2026, 3:40:17 PM ERROR [AppAllExceptionsFilter] Unhandled exception, request path: /api/audit
{
"stack": "UnauthorizedException: Unauthorized\n at JwtAuthGuard.handleRequest (/app/node_modules/@nestjs/passport/dist/auth.guard.js:60:30)",
"response": { "message": "Unauthorized" },
"status": 401,
"message": "Unauthorized",
"name": "UnauthorizedException"
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.