mirror of
https://github.com/kennethnym/aris.git
synced 2026-02-02 05:01:17 +00:00
feat(core): return RefreshResult from ContextBridge.refresh()
Surfaces provider errors through RefreshResult.errors instead of silently ignoring them. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -5,6 +5,15 @@ interface ContextUpdatable {
|
||||
pushContextUpdate(update: Partial<Context>): void
|
||||
}
|
||||
|
||||
export interface ProviderError {
|
||||
key: string
|
||||
error: Error
|
||||
}
|
||||
|
||||
export interface RefreshResult {
|
||||
errors: ProviderError[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridges context providers to a feed controller.
|
||||
*
|
||||
@@ -55,10 +64,11 @@ export class ContextBridge {
|
||||
/**
|
||||
* Gathers current values from all providers and pushes to controller.
|
||||
* Use for manual refresh when user pulls to refresh.
|
||||
* Errors from individual providers are silently ignored.
|
||||
* Returns errors from providers that failed to fetch.
|
||||
*/
|
||||
async refresh(): Promise<void> {
|
||||
async refresh(): Promise<RefreshResult> {
|
||||
const updates: Partial<Context> = {}
|
||||
const errors: ProviderError[] = []
|
||||
|
||||
const entries = Array.from(this.providers.entries())
|
||||
const results = await Promise.allSettled(
|
||||
@@ -69,10 +79,17 @@ export class ContextBridge {
|
||||
const result = results[i]
|
||||
if (result?.status === "fulfilled") {
|
||||
updates[key] = result.value
|
||||
} else if (result?.status === "rejected") {
|
||||
errors.push({
|
||||
key,
|
||||
error: result.reason instanceof Error ? result.reason : new Error(String(result.reason)),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
this.controller.pushContextUpdate(updates)
|
||||
|
||||
return { errors }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ export type { DataSource } from "./data-source"
|
||||
export type { ContextProvider } from "./context-provider"
|
||||
|
||||
// Context Bridge
|
||||
export type { ProviderError, RefreshResult } from "./context-bridge"
|
||||
export { ContextBridge } from "./context-bridge"
|
||||
|
||||
// Reconciler
|
||||
|
||||
Reference in New Issue
Block a user