Skip to content

Commit

Permalink
fix: Improve incorrect ParseRequest typing (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek authored Feb 17, 2020
1 parent bd0649c commit 3fed200
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,20 @@ function extractUserData(
return user;
}

/**
* Options deciding what parts of the request to use when enhancing an event
*/
interface ParseRequestOptions {
request?: boolean | string[];
serverName?: boolean;
transaction?: boolean | TransactionTypes;
user?: boolean | string[];
version?: boolean;
}

/**
* Enriches passed event with request data.
*
*
* @param event Will be mutated and enriched with req data
* @param req Request object
* @param options object containing flags to enable functionality
Expand All @@ -220,13 +230,7 @@ export function parseRequest(
req: {
[key: string]: any;
},
options?: {
request?: boolean | string[];
serverName?: boolean;
transaction?: boolean | TransactionTypes;
user?: boolean | string[];
version?: boolean;
},
options?: ParseRequestOptions,
): Event {
// tslint:disable-next-line:no-parameter-reassignment
options = {
Expand Down Expand Up @@ -277,14 +281,11 @@ export function parseRequest(
* Express compatible request handler.
* @see Exposed as `Handlers.requestHandler`
*/
export function requestHandler(options?: {
request?: boolean;
serverName?: boolean;
transaction?: boolean | TransactionTypes;
user?: boolean | string[];
version?: boolean;
flushTimeout?: number;
}): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void {
export function requestHandler(
options?: ParseRequestOptions & {
flushTimeout?: number;
},
): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void {
return function sentryRequestMiddleware(
req: http.IncomingMessage,
res: http.ServerResponse,
Expand Down

0 comments on commit 3fed200

Please sign in to comment.