chore: Move FetchUtil to util folder.

This commit is contained in:
Ruben Verborgh
2021-07-20 15:33:28 +02:00
parent aec92dd1c3
commit 31dcfbf51e
4 changed files with 5 additions and 5 deletions

View File

@@ -3,8 +3,8 @@ import { v4 } from 'uuid';
import { getLoggerFor } from '../../logging/LogUtil';
import type { ExpiringStorage } from '../../storage/keyvalue/ExpiringStorage';
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
import { fetchDataset } from '../../util/FetchUtil';
import { SOLID } from '../../util/Vocabularies';
import { fetchDataset } from '../util/FetchUtil';
import { OwnershipValidator } from './OwnershipValidator';
const { literal, namedNode, quad } = DataFactory;

View File

@@ -2,8 +2,8 @@ import { DataFactory } from 'n3';
import type { Adapter, AdapterPayload } from 'oidc-provider';
import type { Dataset, Quad } from 'rdf-js';
import { getLoggerFor } from '../../logging/LogUtil';
import { fetchDataset } from '../../util/FetchUtil';
import { SOLID } from '../../util/Vocabularies';
import { fetchDataset } from '../util/FetchUtil';
import type { AdapterFactory } from './AdapterFactory';
import namedNode = DataFactory.namedNode;

View File

@@ -1,29 +0,0 @@
import fetch from '@rdfjs/fetch';
import type { DatasetResponse } from '@rdfjs/fetch-lite';
import type { Dataset } from 'rdf-js';
import { getLoggerFor } from '../../logging/LogUtil';
import { createErrorMessage } from '../../util/errors/ErrorUtil';
const logger = getLoggerFor('FetchUtil');
/**
* Fetches an RDF dataset from the given URL.
*/
export async function fetchDataset(url: string): Promise<Dataset> {
let rawResponse: DatasetResponse<Dataset>;
try {
rawResponse = (await fetch(url)) as DatasetResponse<Dataset>;
} catch (err: unknown) {
logger.error(`Cannot fetch ${url}: ${createErrorMessage(err)}`);
throw new Error(`Cannot fetch ${url}`);
}
let dataset: Dataset;
try {
dataset = await rawResponse.dataset();
} catch (err: unknown) {
logger.error(`Could not parse RDF in ${url}: ${createErrorMessage(err)}`);
// Keeping the error message the same to prevent leaking possible information about intranet
throw new Error(`Cannot fetch ${url}`);
}
return dataset;
}