fix: show clear error dialog for 403 whitelist failures

When the cloud backend returns a 403 (e.g. user not whitelisted), the
error was shown as a generic "Prompt Execution Error" with a cryptic
message. This change:

1. Adds HTTP status to PromptExecutionError so callers can distinguish
   error types
2. Catches 403 responses specifically and shows an "Access Restricted"
   dialog with the backend's actual error message

Backwards compatible: works with both the old backend message
("not authorized") and the new one ("your account is not whitelisted
for this feature" from Comfy-Org/cloud#2941).

Fixes COM-16179

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Miller
2026-03-23 11:35:48 -07:00
parent 818db0d49e
commit 91805b0714
2 changed files with 20 additions and 2 deletions

View File

@@ -281,10 +281,12 @@ export interface ComfyApi extends EventTarget {
export class PromptExecutionError extends Error {
response: PromptResponse
status?: number
constructor(response: PromptResponse) {
constructor(response: PromptResponse, status?: number) {
super('Prompt execution failed')
this.response = response
this.status = status
}
override toString() {
@@ -901,7 +903,7 @@ export class ComfyApi extends EventTarget {
}
}
}
throw new PromptExecutionError(errorResponse)
throw new PromptExecutionError(errorResponse, res.status)
}
return await res.json()

View File

@@ -1647,6 +1647,22 @@ export class ComfyApp {
) {
// Re-scan the full graph instead of using the server's single-node response.
rescanAndSurfaceMissingNodes(this.rootGraph)
} else if (
error instanceof PromptExecutionError &&
error.status === 403
) {
// User is authenticated but not authorized (e.g. not whitelisted).
// Show a clear message instead of a generic error or sign-in prompt.
// The response may be middleware JSON {"message": "..."} which doesn't
// match PromptResponse schema, so access the raw parsed object.
const raw = error.response as Record<string, unknown>
const detail =
typeof raw.message === 'string'
? raw.message
: 'Your account is not authorized for this feature.'
useDialogService().showErrorDialog(new Error(detail), {
title: 'Access Restricted'
})
} else if (
!useSettingStore().get('Comfy.RightSidePanel.ShowErrorsTab') ||
!(error instanceof PromptExecutionError)