UNPKG

3.02 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Event, ExtractedNodeRequestData } from '@sentry/types';
3import * as http from 'http';
4export interface ExpressRequest {
5 baseUrl?: string;
6 connection?: {
7 remoteAddress?: string;
8 };
9 ip?: string;
10 method?: string;
11 originalUrl?: string;
12 route?: {
13 path: string;
14 stack: [{
15 name: string;
16 }];
17 };
18 query?: {
19 [key: string]: unknown;
20 };
21 url?: string;
22 user?: {
23 [key: string]: any;
24 };
25}
26/**
27 * Express-compatible tracing handler.
28 * @see Exposed as `Handlers.tracingHandler`
29 */
30export declare function tracingHandler(): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void;
31declare type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';
32/**
33 * Normalizes data from the request object, accounting for framework differences.
34 *
35 * @param req The request object from which to extract data
36 * @param keys An optional array of keys to include in the normalized data. Defaults to DEFAULT_REQUEST_KEYS if not
37 * provided.
38 * @returns An object containing normalized request data
39 */
40export declare function extractRequestData(req: {
41 [key: string]: any;
42}, keys?: string[]): ExtractedNodeRequestData;
43/**
44 * Options deciding what parts of the request to use when enhancing an event
45 */
46export interface ParseRequestOptions {
47 ip?: boolean;
48 request?: boolean | string[];
49 serverName?: boolean;
50 transaction?: boolean | TransactionNamingScheme;
51 user?: boolean | string[];
52 version?: boolean;
53}
54/**
55 * Enriches passed event with request data.
56 *
57 * @param event Will be mutated and enriched with req data
58 * @param req Request object
59 * @param options object containing flags to enable functionality
60 * @hidden
61 */
62export declare function parseRequest(event: Event, req: ExpressRequest, options?: ParseRequestOptions): Event;
63export declare type RequestHandlerOptions = ParseRequestOptions & {
64 flushTimeout?: number;
65};
66/**
67 * Express compatible request handler.
68 * @see Exposed as `Handlers.requestHandler`
69 */
70export declare function requestHandler(options?: RequestHandlerOptions): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void;
71/** JSDoc */
72interface MiddlewareError extends Error {
73 status?: number | string;
74 statusCode?: number | string;
75 status_code?: number | string;
76 output?: {
77 statusCode?: number | string;
78 };
79}
80/**
81 * Express compatible error handler.
82 * @see Exposed as `Handlers.errorHandler`
83 */
84export declare function errorHandler(options?: {
85 /**
86 * Callback method deciding whether error should be captured and sent to Sentry
87 * @param error Captured middleware error
88 */
89 shouldHandleError?(error: MiddlewareError): boolean;
90}): (error: MiddlewareError, req: http.IncomingMessage, res: http.ServerResponse, next: (error: MiddlewareError) => void) => void;
91export {};
92//# sourceMappingURL=handlers.d.ts.map
\No newline at end of file