1.2.2 • Published 5 months ago

@evlmaistrenko/tools-fetch v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@evlmaistrenko/tools-fetch

NPM Version

Utilities for FetchAPI .

Usage

npm i @evlmaistrenko/tools-fetch
import * as fetchTools from "@evlmaistrenko/tools-fetch";

// Check for error
try {
  await fetch("<some-url>").then((response) =>
    fetchTools.ResponseError.check(response),
  );
} catch (error) {
  if (!(error instanceof fetchTools.ResponseError)) throw error;
  console.log(error.response.status, error.parsed?.message);
}

Extending ResponseError

Assuming that your response body contains comma-separated list of errors.

import * as fetchTools from "@evlmaistrenko/tools-fetch";

class MyResponseError extends fetchTools.ResponseErrorBase<{
  errors: string[];
}> {
  async parse() {
    const json = await this.response.json();
    this.parsedValue = json.errors.split(", ");
  }
}

Api docs

1.2.2

5 months ago

1.2.1

5 months ago

1.2.0

5 months ago

1.1.0

9 months ago

1.0.0

9 months ago