style: fix linting issues met Prettier
This commit is contained in:
parent
fd6691f6aa
commit
96c4caa979
2 changed files with 5 additions and 22 deletions
|
@ -39,10 +39,7 @@ function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLear
|
||||||
*/
|
*/
|
||||||
export async function getLearningObjectById(hruid: string, language: string): Promise<FilteredLearningObject | null> {
|
export async function getLearningObjectById(hruid: string, language: string): Promise<FilteredLearningObject | null> {
|
||||||
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${hruid}&language=${language}`;
|
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${hruid}&language=${language}`;
|
||||||
const metadata = await fetchRemote<LearningObjectMetadata>(
|
const metadata = await fetchRemote<LearningObjectMetadata>(metadataUrl, `Metadata for Learning Object HRUID "${hruid}" (language ${language})`);
|
||||||
metadataUrl,
|
|
||||||
`Metadata for Learning Object HRUID "${hruid}" (language ${language})`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
getLogger().error(`⚠️ WARNING: Learning object "${hruid}" not found.`);
|
getLogger().error(`⚠️ WARNING: Learning object "${hruid}" not found.`);
|
||||||
|
|
|
@ -26,12 +26,7 @@ interface Options {
|
||||||
* @param cacheTTL Time-to-live for the cache in seconds (default: 60 seconds).
|
* @param cacheTTL Time-to-live for the cache in seconds (default: 60 seconds).
|
||||||
* @returns The response data if successful, or null if an error occurs.
|
* @returns The response data if successful, or null if an error occurs.
|
||||||
*/
|
*/
|
||||||
export async function fetchRemote<T>(
|
export async function fetchRemote<T>(url: string, description: string, options?: Options, cacheTTL?: number): Promise<T | null> {
|
||||||
url: string,
|
|
||||||
description: string,
|
|
||||||
options?: Options,
|
|
||||||
cacheTTL?: number,
|
|
||||||
): Promise<T | null> {
|
|
||||||
if (runMode !== 'dev' && !runMode.includes('test')) {
|
if (runMode !== 'dev' && !runMode.includes('test')) {
|
||||||
return fetchWithCache<T>(url, description, options, cacheTTL);
|
return fetchWithCache<T>(url, description, options, cacheTTL);
|
||||||
}
|
}
|
||||||
|
@ -40,12 +35,7 @@ export async function fetchRemote<T>(
|
||||||
return fetchWithLogging(url, description, options);
|
return fetchWithLogging(url, description, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchWithCache<T>(
|
async function fetchWithCache<T>(url: string, description: string, options?: Options, cacheTTL?: number): Promise<T | null> {
|
||||||
url: string,
|
|
||||||
description: string,
|
|
||||||
options?: Options,
|
|
||||||
cacheTTL?: number,
|
|
||||||
): Promise<T | null> {
|
|
||||||
// Combine the URL and parameters to create a unique cache key.
|
// Combine the URL and parameters to create a unique cache key.
|
||||||
// NOTE Using a hash function to keep the key short, since Memcached has a limit on key size
|
// NOTE Using a hash function to keep the key short, since Memcached has a limit on key size
|
||||||
const urlWithParams = `${url}${options?.params ? JSON.stringify(options.params) : ''}`;
|
const urlWithParams = `${url}${options?.params ? JSON.stringify(options.params) : ''}`;
|
||||||
|
@ -70,11 +60,7 @@ async function fetchWithCache<T>(
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchWithLogging<T>(
|
async function fetchWithLogging<T>(url: string, description: string, options?: Options): Promise<T | null> {
|
||||||
url: string,
|
|
||||||
description: string,
|
|
||||||
options?: Options,
|
|
||||||
): Promise<T | null> {
|
|
||||||
try {
|
try {
|
||||||
const config: AxiosRequestConfig = options || {};
|
const config: AxiosRequestConfig = options || {};
|
||||||
const response = await axios.get<T>(url, config);
|
const response = await axios.get<T>(url, config);
|
||||||
|
@ -86,7 +72,7 @@ async function fetchWithLogging<T>(
|
||||||
logger.debug(`❌ ERROR: ${description} not found (404) at "${url}".`);
|
logger.debug(`❌ ERROR: ${description} not found (404) at "${url}".`);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`❌ ERROR: Failed to fetch ${description}. Status: ${error.response.status} - ${error.response.statusText} (URL: "${url}")`,
|
`❌ ERROR: Failed to fetch ${description}. Status: ${error.response.status} - ${error.response.statusText} (URL: "${url}")`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue