UNPKG

scrabble-solver

Version:

Scrabble Solver 2 - Free, open-source, cross-platform, multi-language analysis tool for Scrabble, Scrabble Duel, Super Scrabble, Letter League, Crossplay, Literaki, and Kelimelik. Quickly find the top-scoring words using the given board and tiles.

29 lines (22 loc) 651 B
import { isError } from '@scrabble-solver/types'; export const fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => { let response: Response; try { response = await window.fetch(input, init); } catch (error) { const message = isError(error) ? error.message : 'Unknown error'; throw new Error(`Network error: ${message}`); } if (response.ok) { return response; } try { const json = await response.json(); if (isError(json)) { throw new Error(json.message); } } finally { // do nothing } throw new Error(`HTTP ${response.status}: ${response.statusText}`); };