mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
fix(core): surface authorization cause in error message (#49214)
This commit is contained in:
committed by
GitHub
Unverified
parent
6c9115eb75
commit
e31ad14c1d
@@ -111,7 +111,13 @@ export class CodeRequiredError extends Schema.TaggedError<CodeRequiredError>()("
|
||||
|
||||
export class AuthorizationError extends Schema.TaggedError<AuthorizationError>()("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<AttemptNotFoundError>()("Integration.AttemptNotFound", {
|
||||
integrationID: ID,
|
||||
|
||||
@@ -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")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user