mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 06:41:07 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
24 lines
740 B
TypeScript
24 lines
740 B
TypeScript
/** Per-request hooks captured by the feature that owns the active surface. */
|
|
export type RequestGuard = {
|
|
beforeRequest: () => void
|
|
isActive: () => boolean
|
|
handleError: (status: number, data: unknown, error: object) => boolean
|
|
}
|
|
|
|
type RequestGuardFactory = (
|
|
url: string,
|
|
isPublicAPI: boolean,
|
|
method: string,
|
|
) => RequestGuard | undefined
|
|
|
|
let requestGuardFactory: RequestGuardFactory | undefined
|
|
|
|
/** Register at the feature entrypoint, before its request owners mount. */
|
|
export function registerRequestGuard(factory: RequestGuardFactory) {
|
|
requestGuardFactory = factory
|
|
}
|
|
|
|
export function captureRequestGuard(url: string, isPublicAPI = false, method = 'GET') {
|
|
return requestGuardFactory?.(url, isPublicAPI, method)
|
|
}
|