Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "lib/utils"

Index

Functions

Const asyncMiddlewareWrapper

  • This function wraps middlewares to enable async calls in there. It is taken from https://github.com/tranvansang/middleware-async

    FIXME: [DATAHUB-79] Once async middlewares land in express we van remove this. If we run into errors it might be necessary to use the original repo and to contribute. FIXME: [DATAHUB-81] Create robust Typescript function signature

    Parameters

    Returns (Anonymous function)

asyncWrapper

  • asyncWrapper(callback: (req: Request, res: Response, next: NextFunction) => Promise<void>): (req: Request, res: Response, next: NextFunction) => void
  • This function can be used to wrap request handlers into an async function so we can make async/await calls to prisma. It is taken from https://zellwk.com/blog/async-await-express/ FIXME: [DATAHUB-80] Once async handlers land in express we should fix this. There are also some packages that seem more robust then my snippet here.

    Parameters

    • callback: (req: Request, res: Response, next: NextFunction) => Promise<void>
        • (req: Request, res: Response, next: NextFunction): Promise<void>
        • Parameters

          • req: Request
          • res: Response
          • next: NextFunction

          Returns Promise<void>

    Returns (req: Request, res: Response, next: NextFunction) => void

      • (req: Request, res: Response, next: NextFunction): void
      • Parameters

        • req: Request
        • res: Response
        • next: NextFunction

        Returns void

createPayload

  • createPayload<T>(obj: T): { data: T }
  • Creates a response payload with named objects

    example

    createPayload({application});

    example

    createPayload({applications:[]})

    Type parameters

    • T

    Parameters

    • obj: T

    Returns { data: T }

    • data: T

Const errorHandler

  • errorHandler(error: Error | HttpError, _request: Request<ParamsDictionary, any, any, ParsedQs>, response: Response<any>, _next: NextFunction): void
  • General error handler for all thrown errors in the application

    Parameters

    • error: Error | HttpError
    • _request: Request<ParamsDictionary, any, any, ParsedQs>
    • response: Response<any>
    • _next: NextFunction

    Returns void

Generated using TypeDoc