Sha256: 6f8e30aaf6dc85ff7d2258c64dbf3e4e22690f8d79f0d9cff3a4863d1c10cca3
Contents?: true
Size: 1.67 KB
Versions: 26
Compression:
Stored size: 1.67 KB
Contents
import { RequestHandler, RequestHandlerExecutionResult, } from '../handlers/RequestHandler' export interface HandlersExecutionResult { handler: RequestHandler parsedResult?: any response?: Response } export interface ResponseResolutionContext { baseUrl?: string } /** * Executes the list of request handlers against the given request. * Returns the execution result object containing any matching request * handler and any mocked response it returned. */ export const executeHandlers = async <Handlers extends Array<RequestHandler>>({ request, requestId, handlers, resolutionContext, }: { request: Request requestId: string handlers: Handlers resolutionContext?: ResponseResolutionContext }): Promise<HandlersExecutionResult | null> => { let matchingHandler: RequestHandler | null = null let result: RequestHandlerExecutionResult<any> | null = null for (const handler of handlers) { result = await handler.run({ request, requestId, resolutionContext }) // If the handler produces some result for this request, // it automatically becomes matching. if (result !== null) { matchingHandler = handler } // Stop the lookup if this handler returns a mocked response. // If it doesn't, it will still be considered the last matching // handler until any of them returns a response. This way we can // distinguish between fallthrough handlers without responses // and the lack of a matching handler. if (result?.response) { break } } if (matchingHandler) { return { handler: matchingHandler, parsedResult: result?.parsedResult, response: result?.response, } } return null }
Version data entries
26 entries across 26 versions & 1 rubygems