feat: better err reporting & init private endpoint

This commit is contained in:
swve 2023-04-09 01:36:47 +02:00
parent 8f8257b9e7
commit 6137c907d2
4 changed files with 30 additions and 9 deletions

View file

@ -9,10 +9,15 @@ import { RequestBody } from "@services/utils/requests";
//TODO : depreciate this function
export async function getCourseChaptersMetadata(course_id: any) {
const data: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null))
.then((result) => result.json())
.catch((error) => console.log("error", error));
const response = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null));
if (!response.ok) {
const error: any = new Error(`Error ${response.status}: ${response.statusText}`, {});
error.status = response.status;
throw error;
}
const data = await response.json();
return data;
}
@ -20,7 +25,7 @@ export async function updateChaptersMetadata(course_id: any, data: any) {
const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data))
.then((result) => result.json())
.catch((error) => console.log("error", error));
return result;
}