fix: opslitsing learningpath controller met extra service + api helper

This commit is contained in:
Gabriellvl 2025-03-01 17:52:55 +01:00
parent 91eb374b7e
commit f7d6cbce65
4 changed files with 98 additions and 116 deletions

View file

@ -1,4 +1,4 @@
import axios from 'axios';
import axios, {AxiosRequestConfig} from 'axios';
// !!!! when logger is done -> change
@ -8,11 +8,18 @@ import axios from 'axios';
*
* @param url The API endpoint to fetch from.
* @param description A short description of what is being fetched (for logging).
* @param params
* @returns The response data if successful, or null if an error occurs.
*/
export async function fetchWithLogging<T>(url: string, description: string): Promise<T | null> {
export async function fetchWithLogging<T>(
url: string,
description: string,
params?: Record<string,any>
): Promise<T | null> {
try {
const response = await axios.get<T>(url);
const config: AxiosRequestConfig = params ? { params } : {};
const response = await axios.get<T>(url, config);
return response.data;
} catch (error: any) {
if (error.response) {