Skip to content

Commit c901a86

Browse files
committed
fix(credentials): say an expired saved token's date is UTC and keep it the provider's refusal
The expired-token error extended UserFailure, but the boundary always carries the provider refusal's attribution onto it, so the base did nothing and its docs contradicted the logged classification. It is now a plain Error, and the run message names the date as UTC.
1 parent f670711 commit c901a86

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎apps/sim/lib/credentials/__integration__/saved-token-expiry.integration.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ const DAY_MS = 24 * 60 * 60 * 1000
3535
/** Expiry GitHub reports for each fixture token; a token without one never expires. */
3636
const tokenExpirations = new Map<string, Date>()
3737

38-
/** GitHub's header form, whole seconds in UTC. */
38+
/** GitHub's header form, whole seconds with a numeric offset, here UTC's. */
3939
function githubExpirationHeader(expiresAt: Date): string {
40-
return `${expiresAt.toISOString().slice(0, 19).replace('T', ' ')} UTC`
40+
return `${expiresAt.toISOString().slice(0, 19).replace('T', ' ')} +0000`
4141
}
4242

4343
function expiringToken(daysAhead: number): { token: string; expiresAt: Date } {
@@ -239,7 +239,7 @@ describe('saved token expiry', () => {
239239
const explained = await explainExpiredSavedToken(credentialId, refusal)
240240

241241
expect(explained?.message).toBe(
242-
'The saved GitHub personal access token expired on 2026-01-15. Create a new personal access token and reconnect the credential.'
242+
'The saved GitHub personal access token expired on 2026-01-15 UTC. Create a new personal access token and reconnect the credential.'
243243
)
244244
expect(explained).toMatchObject({
245245
status: 401,

‎apps/sim/lib/credentials/saved-token-expiry.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { db } from '@sim/db'
22
import { credential } from '@sim/db/schema'
33
import { and, eq, lte } from 'drizzle-orm'
4-
import { UserFailure } from '@/lib/core/errors/user-failure'
54
import { getTokenServiceAccountDescriptor } from '@/lib/credentials/token-service-accounts/descriptors'
65

76
/** The provider's own failure that a saved token's expiry explains. */
@@ -13,11 +12,12 @@ interface ProviderRefusal {
1312

1413
/**
1514
* A provider refused a saved token that is past the expiry its vendor stated when it was saved.
16-
* Only replacing the token restores the credential, so it is the user's to fix. It keeps the
17-
* provider's `status`, `statusText`, and `data`, so callers that branch on the HTTP failure still
18-
* see it; the boundary that replaces the refusal with it carries the refusal's log attribution over.
15+
* Its message tells the user to replace the token, while the failure stays the provider's refusal:
16+
* it keeps the provider's `status`, `statusText`, and `data`, so callers that branch on the HTTP
17+
* failure still see it, and the boundary that replaces the refusal with it carries the refusal's
18+
* log attribution over.
1919
*/
20-
class SavedTokenExpiredError extends UserFailure {
20+
class SavedTokenExpiredError extends Error {
2121
readonly status: number
2222
readonly statusText?: string
2323
readonly data?: unknown
@@ -59,7 +59,7 @@ export async function explainExpiredSavedToken(
5959
const token = descriptor ? `${descriptor.serviceLabel} ${descriptor.tokenNoun}` : 'token'
6060
const replacement = descriptor?.tokenNoun ?? 'token'
6161
return new SavedTokenExpiredError(
62-
`The saved ${token} expired on ${row.expiresAt.toISOString().slice(0, 10)}. Create a new ${replacement} and reconnect the credential.`,
62+
`The saved ${token} expired on ${row.expiresAt.toISOString().slice(0, 10)} UTC. Create a new ${replacement} and reconnect the credential.`,
6363
refusal
6464
)
6565
}

‎apps/sim/tools/index.test.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ vi.mock('@/tools/utils.server', async (importOriginal) => {
486486

487487
import type { QueryClient } from '@tanstack/react-query'
488488
import { adoptToolFailure, classifyFailure, logFailureOnce } from '@/lib/core/errors/failure-log'
489-
import { UserFailure } from '@/lib/core/errors/user-failure'
490489
import * as getQueryClientModule from '@/app/_shell/providers/get-query-client'
491490
import { ApiBlockHandler } from '@/executor/handlers/api/handler'
492491
import { buildBlockExecutionError } from '@/executor/utils/errors'
@@ -3837,7 +3836,7 @@ describe('Internal Route Trust', () => {
38373836

38383837
it('reports the expiry instead of the bare refusal', async () => {
38393838
mockExplainExpiredSavedToken.mockImplementation(async (_id, refusal) =>
3840-
Object.assign(new UserFailure(EXPIRED), refusal)
3839+
Object.assign(new Error(EXPIRED), refusal)
38413840
)
38423841

38433842
const result = await callWith('service_account', 401)
@@ -3851,7 +3850,7 @@ describe('Internal Route Trust', () => {
38513850

38523851
it("logs the explained refusal as the provider's refusal, with its response body", async () => {
38533852
mockExplainExpiredSavedToken.mockImplementation(async (_id, refusal) =>
3854-
Object.assign(new UserFailure(EXPIRED), refusal)
3853+
Object.assign(new Error(EXPIRED), refusal)
38553854
)
38563855
mockToolsLogger.warn.mockClear()
38573856

@@ -3964,7 +3963,7 @@ describe('Internal Route Trust', () => {
39643963
it('reports an expired saved token instead of the bare refusal', async () => {
39653964
mockExplainExpiredSavedToken.mockReset()
39663965
mockExplainExpiredSavedToken.mockImplementation(async (_id, refusal) =>
3967-
Object.assign(new UserFailure('The saved token expired.'), refusal)
3966+
Object.assign(new Error('The saved token expired.'), refusal)
39683967
)
39693968

39703969
const result = await runWith('service_account', 401)

0 commit comments

Comments
 (0)