diff --git a/packages/core/src/integration.ts b/packages/core/src/integration.ts index fe49e220a21..e93549b1143 100644 --- a/packages/core/src/integration.ts +++ b/packages/core/src/integration.ts @@ -111,7 +111,13 @@ export class CodeRequiredError extends Schema.TaggedError()(" export class AuthorizationError extends Schema.TaggedError()("Integration.Authorization", { cause: Schema.Defect(), -}) {} +}) { + override get message() { + const cause = this.cause + if (cause instanceof Error && cause.message) return cause.message + return "Authorization failed" + } +} export class AttemptNotFoundError extends Schema.TaggedError()("Integration.AttemptNotFound", { integrationID: ID, diff --git a/packages/core/test/integration.test.ts b/packages/core/test/integration.test.ts index f670f8f1847..5458ada55e1 100644 --- a/packages/core/test/integration.test.ts +++ b/packages/core/test/integration.test.ts @@ -1,4 +1,4 @@ -import { describe, expect } from "bun:test" +import { describe, expect, test } from "bun:test" import { Cause, Clock, Duration, Effect, Exit, Fiber, Layer, Scope, Stream } from "effect" import { TestClock } from "effect/testing" import { Credential } from "@opencode/core/credential" @@ -674,3 +674,16 @@ describe("Integration", () => { ) }) }) + +describe("AuthorizationError", () => { + test("reports the underlying cause message", () => { + expect(new Integration.AuthorizationError({ cause: new Error("Request failed: 401") }).message).toBe( + "Request failed: 401", + ) + }) + + test("falls back when the cause carries no message", () => { + expect(new Integration.AuthorizationError({ cause: new Error() }).message).toBe("Authorization failed") + expect(new Integration.AuthorizationError({ cause: undefined }).message).toBe("Authorization failed") + }) +})