isomorphic-fetch

This commit is contained in:
Aleksandr Kraiz
2022-05-10 14:26:53 +04:00
parent 81e96def62
commit c25360a026
4 changed files with 36 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
import { Schema, z } from 'zod';
import fetch, { FetchError, RequestInit } from 'node-fetch';
import fetch from 'isomorphic-unfetch';
import {
err, fromPromise, fromThrowable, ok,
} from 'neverthrow';
@@ -32,17 +33,10 @@ export default async function fetchWithValidation<DataOut, DataIn, ErrorOut, Err
...(options ? options.headers : {}),
},
}), (e) => {
if (e instanceof FetchError) {
if (e instanceof Error) {
return err({
type: 'fetchError' as const,
url,
message: `${e.message} (${e.type})`,
error: e,
});
} if (e instanceof Error) {
return err({
type: 'unknownFetchError' as const,
url,
message: e.message,
error: e,
});