Background
I started working at a company that doesn't have many patterns and I see the return of fetch
calls in two ways. One returning just the fetch
call and another returning a fetch
call wrapped by Promise
using resolve
and reject
, and this made me get confused.
Question
Is doing this
const returnFetchWrappedByPromise = () => {
return new Promise((resolve, reject) => {
return fetch("url")
.then(resolve(true))
.catch(reject(false))
})
}
The same as this
const returnFetch = () => {
return fetch("url")
.then(() => true)
.catch(() => false)
}
?
If not, what is the difference?
If yes, which one should I use?
Observation: I used true
and false
just to make an example, but in reality, is some result and some error.