sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.31k stars 173 forks source link

try result tuple is wrong #254

Closed sysmat closed 1 year ago

sysmat commented 1 year ago
import * as r from 'radash';
...
// radash way not working as expected
const [err, god] = await r.try(updateHuman)(prop.index, human);
console.error('error=', err); // err is undefined
console.log('god=', god); //  god={ "detail": "Method 'POST' not allowed."}

// old way works fine
updateHuman(prop.index, human).then(ok => {
        prop.setHuman(human);
        prop.edit(false);
      }).catch(err => {
        console.log('updateHuman=', err);
        setError('error when updating human')
});

export const updateHuman = async (id: number, human: Human): Promise<Human> => (
    await fetch(`https://swapi.dev/api/people/${id}/`, {
        method: 'POST',
        headers: jwt,
        body: JSON.stringify(human)
    })).json();
sysmat commented 1 year ago

My mistake