-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥅 Check if user deleted playlist without 403 code
- Loading branch information
Showing
4 changed files
with
49 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
import type { Response } from 'node-fetch' | ||
|
||
export const handleRepsonse = async <T>(method: () => Promise<Response>): Promise<T> => { | ||
try { | ||
const res = await method() | ||
if (res.status < 300) { | ||
if (res.headers.get('content-type')?.startsWith('application/json')) | ||
return await res.json() | ||
else return true as T | ||
} else { | ||
let error: any | ||
try { | ||
error = (await res.json()).error | ||
} catch { | ||
error = { status: res.status, statusText: res.statusText } | ||
} | ||
throw error; | ||
} | ||
} catch (error) { | ||
throw error | ||
} | ||
try { | ||
const res = await method() | ||
if (res.status < 300) { | ||
if (res.headers.get('content-type')?.startsWith('application/json')) | ||
return await res.json() | ||
else return true as T | ||
} else { | ||
let error: any | ||
try { | ||
error = (await res.json()).error | ||
} catch { | ||
error = { status: res.status, statusText: res.statusText } | ||
} | ||
throw error | ||
} | ||
} catch (error) { | ||
throw error | ||
} | ||
} | ||
|
||
export class PlaylistDeletedError extends Error {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters