The throwermw()
middleware will throw Errors when a response returns with a status in the 400 to 599 tange.
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)
}
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/'
}))
}
}))