Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 694 Bytes

thrower.md

File metadata and controls

34 lines (25 loc) · 694 Bytes

Thrower middleware

The throwermw() middleware will throw Errors when a response returns with a status in the 400 to 599 tange.

Usage

import * as metro from '@muze-nl/metro'
import throwermw from '@muze-nl/metro/src/mw/thrower.mjs'

const client = metro.client().with( throwermw() )

try {
	let response = await client.get('https://example.com/404/')
	result = response.text()
} catch(err) {
	console.error(err)
}

Configuration Options

You can set custom handling for specific status codes, like this:

const client = metro.client().with( throwermw({
	404: (req) => {
		return client.get(req.with({
			url: 'https://example.com/'
		}))
	}
}))