Conversation
|
I don't know why it recreated with different spacing, maybe it was that recently pushed config, which uses 2 spacing? |
| return fetch(`${base_path}${endpoint}`, { | ||
| method, | ||
| mode: "cors", | ||
| ...(additional !== undefined && { ...additional }), |
There was a problem hiding this comment.
...additional should be enough even if it is undefined. OR, if you're afraid of undefined, you can provide a default value: const makeApiRequest = async (base_path, endpoint, method, additional = {}) => ...
| const uploadVideo = async (video) => { | ||
| const formData = new FormData(); | ||
| formData.append('formFile', video); | ||
| const getUntrashedUserVideos = async (userId) => { |
There was a problem hiding this comment.
Why is this function async, considering you're not using await ? Same applies to other functions in this file
There was a problem hiding this comment.
This function receives a response from makeApiRequest. response is a promise which is then delegated (passed) to the caller of this function. Function that returns a promise has to be marked with async to indicate that it is awaitable and does not return the 'raw result' but rather - a promise.
| const formData = new FormData(); | ||
| formData.append('formFile', video); | ||
| const getUntrashedUserVideos = async (userId) => { | ||
| const response = makeApiRequest( |
There was a problem hiding this comment.
Seems like it could be simplified to:
return makeApiRequest(...)
| }); | ||
| } | ||
| if (typeof response.text === "function") { | ||
| return response.text().then((text) => { |
There was a problem hiding this comment.
Why do you assume that text() returns a promise/thenable?
| return response; | ||
| }).catch(error => { | ||
| console.log(error); | ||
| return fetch(`${API_URL_PREFIX}${endpoint}`, { |
There was a problem hiding this comment.
The function would probably read better with await and try-catch. An idea - it could take onSuccess and onError callbacks as parameters to make it more reusable
No description provided.