mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add logging
* feat: Add logging * refactor: Configure the logger for the tests once globally * feat: Add logging * fix: Fix ESLint errors due to merge conflicts * Review log and error messages. * refactor: Cleanup a bit * refactor: Change to logger info calls Co-authored-by: Ruben Verborgh <ruben@verborgh.org>
This commit is contained in:
@@ -8,6 +8,7 @@ import type { SparqlUpdatePatch } from '../../ldp/http/SparqlUpdatePatch';
|
||||
import type { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
@@ -20,6 +21,8 @@ import { PatchHandler } from './PatchHandler';
|
||||
* Currently all DELETE/INSERT types are supported that have empty where bodies and no variables.
|
||||
*/
|
||||
export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
private readonly source: ResourceStore;
|
||||
private readonly locker: ResourceLocker;
|
||||
|
||||
@@ -31,14 +34,15 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
|
||||
public async canHandle(input: {identifier: ResourceIdentifier; patch: SparqlUpdatePatch}): Promise<void> {
|
||||
if (typeof input.patch.algebra !== 'object') {
|
||||
throw new UnsupportedHttpError('Only SPARQL update patch requests are supported.');
|
||||
throw new UnsupportedHttpError('Only SPARQL update patch requests are supported');
|
||||
}
|
||||
}
|
||||
|
||||
public async handle(input: {identifier: ResourceIdentifier; patch: SparqlUpdatePatch}): Promise<void> {
|
||||
const op = input.patch.algebra;
|
||||
if (!this.isDeleteInsert(op)) {
|
||||
throw new UnsupportedHttpError('Only DELETE/INSERT SPARQL update operations are supported.');
|
||||
this.logger.warn(`Unsupported operation: ${op.type}`);
|
||||
throw new UnsupportedHttpError('Only DELETE/INSERT SPARQL update operations are supported');
|
||||
}
|
||||
|
||||
const def = defaultGraph();
|
||||
@@ -46,14 +50,17 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
const inserts = op.insert ?? [];
|
||||
|
||||
if (!deletes.every((pattern): boolean => pattern.graph.equals(def))) {
|
||||
throw new UnsupportedHttpError('GRAPH statements are not supported.');
|
||||
this.logger.warn('GRAPH statement in DELETE clause');
|
||||
throw new UnsupportedHttpError('GRAPH statements are not supported');
|
||||
}
|
||||
if (!inserts.every((pattern): boolean => pattern.graph.equals(def))) {
|
||||
throw new UnsupportedHttpError('GRAPH statements are not supported.');
|
||||
this.logger.warn('GRAPH statement in INSERT clause');
|
||||
throw new UnsupportedHttpError('GRAPH statements are not supported');
|
||||
}
|
||||
if (op.where ?? deletes.some((pattern): boolean =>
|
||||
someTerms(pattern, (term): boolean => term.termType === 'Variable'))) {
|
||||
throw new UnsupportedHttpError('WHERE statements are not supported.');
|
||||
this.logger.warn('WHERE statements are not supported');
|
||||
throw new UnsupportedHttpError('WHERE statements are not supported');
|
||||
}
|
||||
|
||||
const lock = await this.locker.acquire(input.identifier);
|
||||
|
||||
Reference in New Issue
Block a user