Options
All
  • Public
  • Public/Protected
  • All
Menu

fetchmap

Index

Functions

  • createFetchmap<Fetch>(fetch: Fetch): (<Response, Map>(map: Map, input: Input, init?: Init) => Promise<PrettyType<FetchResult<Response, Map>>>)
  • Creates a fetchmap from third-party fetch function.

    Type Parameters

    • Fetch extends ((input: never, init?: undefined) => Promise<BasicResponse>)

    Parameters

    • fetch: Fetch

      A fetch-like function. Should take two parameters and return a Promise<BasicResponse>. BasicResponse requires only status, arrayBuffer, blob, formData, json and text properties of standard Response type to be defined.

    Returns (<Response, Map>(map: Map, input: Input, init?: Init) => Promise<PrettyType<FetchResult<Response, Map>>>)

      • <Response, Map>(map: Map, input: Input, init?: Init): Promise<PrettyType<FetchResult<Response, Map>>>
      • Non-throwing fetch wrapper

        Type Parameters

        • Response extends any

        • Map extends Partial<MultiMapResponse<Response>>

        Parameters

        • map: Map

          An object to map response.status to validating transform. Keys can be response status numbers + ok and notOk. If no mapping for received response status specified, it will use ok transform for statuses in the inclusive range from 200 to 299 and notOk otherwise. Both ok and notOk just return SuccessResult with received Response object by default. Each transform is an object that represents a mapping from body reading method (json, text, blob, arrayBuffer, formData) to (body: BodyType, response: Response) => Result validating transform or an object without body mapping - { noBody: (response: Response) => Result }. If validation fails it should return FailureResult and SuccessResult otherwise.

        • input: Input

          fetch function first argument

        • Optional init: Init

          fetch function second argument

        Returns Promise<PrettyType<FetchResult<Response, Map>>>

        Success or failure result.

        • If fetch function itself did throw an error then a failure result containing an object with clientError property set to thrown value will be returned.
        • If body reading method or validating transform did throw an error then a failure result containing an object with mapError property set to thrown value will be returned.
        • If validating transform did not throw an error but fail to validate the received data then a failure result containing an object with validationError property set to validation error will be returned.
        • If response status is outside inclusive range from 200 to 299 and transform function succeed to validate the received data then a failure result containing an object with serverError property set to transformed value will be returned.
        • If response status is inside inclusive range from 200 to 299 and transform function succeed to validate the received data then a success result containing the transformed value will be returned.

Generated using TypeDoc