Skip to content

Commit d8b48ed

Browse files
Add errorType field to InteractionSummary to handle errors based on error type and not content
1 parent a653890 commit d8b48ed

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

browser-extension/src/background.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AgentSession } from "./scripts/agent-session";
55
import { findAgentSession, saveAgentSession, removeAgentSession, } from "./scripts/agent-session-repository";
66
import { saveAgentPrompts } from "./scripts/prompt-repository";
77
import { BrowserMessage, ToggleSidebar, ActiveTabListener, ActivateAgent, AgentActivation, InteractionSummary, } from "./scripts/browser-message";
8-
import { HttpServiceError, NetworkError } from "./scripts/http";
8+
import { BaseError } from "./scripts/http";
99
import { isActiveTabListener, setTabListenerActive, removeTabListenerStatus, } from "./scripts/tab-listener-status-repository";
1010
import { removeTabState } from "./scripts/tab-state-repository";
1111

@@ -175,7 +175,8 @@ async function asyncProcessRequest(req: RequestEvent) {
175175
tabId,
176176
new InteractionSummary(
177177
false,
178-
(e instanceof HttpServiceError || e instanceof NetworkError) ? e.detail : undefined
178+
e instanceof BaseError ? e.detail : undefined,
179+
e instanceof BaseError ? e.getType() : undefined
179180
)
180181
);
181182
}

browser-extension/src/pages/Index.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ const onAgentActivation = (msg: AgentActivation) => {
165165
}
166166
167167
const onInteractionSummary = (msg: InteractionSummary) => {
168-
const text = msg.text
169-
? (msg.text === "Failed to fetch" ? t('networkError') : msg.text)
170-
: t('interactionSummaryError', { contactEmail: agent.value!.manifest.contactEmail })
168+
let text = msg.text ?? ''
169+
170+
if (!msg.success) {
171+
text = msg.errorType === 'NetworkError' ? t('networkError') : t('interactionSummaryError', {
172+
contactEmail: agent.value!.manifest.contactEmail
173+
})
174+
}
175+
171176
const lastMessage = messages.value[messages.value.length - 1]
172177
const messagePosition = lastMessage.isComplete ? messages.value.length : messages.value.length - 1
173178
messages.value.splice(messagePosition, 0, msg.success ? ChatMessage.agentMessage(text) : ChatMessage.agentErrorMessage(text))

browser-extension/src/scripts/browser-message.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ export class AgentActivation extends BrowserMessage {
102102
export class InteractionSummary extends BrowserMessage {
103103
text?: string
104104
success: boolean
105+
errorType?: string
105106

106-
constructor(success: boolean, text?: string) {
107+
constructor(success: boolean, text?: string, errorType?: string) {
107108
super("interactionSummary")
108109
this.text = text
109110
this.success = success
111+
this.errorType = errorType
110112
}
111113

112114
public static fromJsonObject(obj: any): InteractionSummary {
113-
return new InteractionSummary(obj.success, obj.text)
115+
return new InteractionSummary(obj.success, obj.text, obj.errorType)
114116
}
115117
}
116118

browser-extension/src/scripts/http.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@ const fetchResponse = async (url: string, options?: RequestInit) => {
3333
return ret
3434
}
3535

36-
class BaseError extends Error {
36+
export class BaseError extends Error {
3737
detail?: string
38+
readonly type: string = 'BaseError'
3839

3940
constructor(detail?: string) {
4041
super()
4142
this.detail = detail
4243
}
44+
45+
getType(): string {
46+
return this.type
47+
}
4348
}
4449

45-
export class HttpServiceError extends BaseError {}
50+
export class HttpServiceError extends BaseError {
51+
readonly type: string = 'HttpServiceError'
52+
}
4653

47-
export class NetworkError extends BaseError {}
54+
export class NetworkError extends BaseError {
55+
readonly type: string = 'NetworkError'
56+
}
4857

4958
export async function* fetchStreamJson(url: string, options?: RequestInit): AsyncIterable<any> {
5059
let resp = await fetchResponse(url, options)

0 commit comments

Comments
 (0)