@eggjs/onerror
Version:
error handler for egg
155 lines (154 loc) • 3.81 kB
TypeScript
import { type StackFrame } from 'stack-trace';
import type { OnerrorError } from 'koa-onerror';
import type { Context } from '@eggjs/core';
export interface FrameSource {
pre: string[];
line: string;
post: string[];
}
export interface Frame extends StackFrame {
context?: FrameSource;
}
export declare class ErrorView {
ctx: Context;
error: OnerrorError;
request: Context['request'];
app: Context['app'];
assets: Map<string, string>;
viewTemplate: string;
codeContext: number;
_filterHeaders: string[];
constructor(ctx: Context, error: OnerrorError, template: string);
/**
* get html error page
*
* @return {String} html page
*/
toHTML(): string;
/**
* compile view
*
* @param {String} tpl - template
* @param {Object} locals - data used by template
*/
compileView(tpl: string, locals: Record<string, unknown>): string;
/**
* check if the frame is node native file.
*
* @param {Frame} frame - current frame
*/
isNode(frame: Frame): boolean;
/**
* check if the frame is app modules.
*
* @param {Object} frame - current frame
*/
isApp(frame: Frame): boolean;
/**
* cache file asserts
*
* @param {String} key - assert key
* @param {String} value - assert content
*/
setAssets(key: string, value: string): void;
/**
* get cache file asserts
*
* @param {String} key - assert key
*/
getAssets(key: string): string | undefined;
/**
* get frame source
*
* @param {Object} frame - current frame
*/
getFrameSource(frame: StackFrame): FrameSource;
/**
* parse error and return frame stack
*/
parseError(): Frame[];
/**
* get stack context
*
* @param {Object} frame - current frame
*/
getContext(frame: Frame): {
start?: undefined;
pre?: undefined;
line?: undefined;
post?: undefined;
} | {
start: number;
pre: string;
line: string;
post: string;
};
/**
* get frame classes, let view identify the frame
*
* @param {any} frame - current frame
* @param {any} index - current index
*/
getFrameClasses(frame: Frame, index: number): string;
/**
* serialize frame and return meaningful data
*
* @param {Object} frame - current frame
*/
serializeFrame(frame: Frame): {
extname: string;
file: string;
method: string;
line: number;
column: number;
context: {
start?: undefined;
pre?: undefined;
line?: undefined;
post?: undefined;
} | {
start: number;
pre: string;
line: string;
post: string;
};
classes: string;
};
/**
* serialize base data
*
* @param {Object} stack - frame stack
* @param {Function} frameFormatter - frame formatter function
*/
serializeData(stack: Frame[], frameFormatter: (frame: Frame, index: number) => any): {
code: any;
message: string;
name: string;
status: number;
frames: any[];
};
/**
* serialize request object
*/
serializeRequest(): {
url: string;
httpVersion: string;
method: string;
connection: string | undefined;
headers: {
key: string;
value: string | string[] | undefined;
}[];
cookies: {
key: string;
value: string | undefined;
}[];
};
/**
* serialize app info object
*/
serializeAppInfo(): {
baseDir: string;
config: string;
};
}