mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add better support for non-native errors
This commit is contained in:
@@ -11,7 +11,7 @@ import { getLoggerFor } from '../logging/LogUtil';
|
||||
import { INTERNAL_QUADS } from '../util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../util/errors/BadRequestHttpError';
|
||||
import { ConflictHttpError } from '../util/errors/ConflictHttpError';
|
||||
import { isNativeError } from '../util/errors/ErrorUtil';
|
||||
import { createErrorMessage } from '../util/errors/ErrorUtil';
|
||||
import { ForbiddenHttpError } from '../util/errors/ForbiddenHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
@@ -344,10 +344,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
quads = await parseQuads(representation.data, { format: contentType, baseIRI: identifier.value });
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (isNativeError(error)) {
|
||||
throw new BadRequestHttpError(`Can only create containers with RDF data. ${error.message}`);
|
||||
}
|
||||
throw error;
|
||||
throw new BadRequestHttpError(`Can only create containers with RDF data. ${createErrorMessage(error)}`);
|
||||
}
|
||||
|
||||
// Solid, §5.3: "Servers MUST NOT allow HTTP POST, PUT and PATCH to update a container’s containment triples;
|
||||
@@ -481,8 +478,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
deleted.push(identifier);
|
||||
} catch (error: unknown) {
|
||||
if (!NotFoundHttpError.isInstance(error)) {
|
||||
const errorMsg = isNativeError(error) ? error.message : error;
|
||||
this.logger.error(`Problem deleting auxiliary resource ${identifier.path}: ${errorMsg}`);
|
||||
this.logger.error(`Error deleting auxiliary resource ${identifier.path}: ${createErrorMessage(error)}`);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -19,7 +19,7 @@ import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdenti
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { ConflictHttpError } from '../../util/errors/ConflictHttpError';
|
||||
import { isNativeError } from '../../util/errors/ErrorUtil';
|
||||
import { createErrorMessage } from '../../util/errors/ErrorUtil';
|
||||
import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError';
|
||||
@@ -300,9 +300,7 @@ export class SparqlDataAccessor implements DataAccessor {
|
||||
try {
|
||||
return guardStream(await this.fetcher.fetchTriples(this.endpoint, query));
|
||||
} catch (error: unknown) {
|
||||
if (isNativeError(error)) {
|
||||
this.logger.error(`SPARQL endpoint ${this.endpoint} error: ${error.message}`);
|
||||
}
|
||||
this.logger.error(`SPARQL endpoint ${this.endpoint} error: ${createErrorMessage(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -317,9 +315,7 @@ export class SparqlDataAccessor implements DataAccessor {
|
||||
try {
|
||||
return await this.fetcher.fetchUpdate(this.endpoint, query);
|
||||
} catch (error: unknown) {
|
||||
if (isNativeError(error)) {
|
||||
this.logger.error(`SPARQL endpoint ${this.endpoint} error: ${error.message}`);
|
||||
}
|
||||
this.logger.error(`SPARQL endpoint ${this.endpoint} error: ${createErrorMessage(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +156,15 @@ export function matchesMediaType(mediaA: string, mediaB: string): boolean {
|
||||
}
|
||||
return subTypeA === subTypeB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given content type is an internal content type such as internal/quads.
|
||||
* Response will be `false` if the input type is undefined.
|
||||
*
|
||||
* Do not use this for media ranges.
|
||||
*
|
||||
* @param contentType - Type to check.
|
||||
*/
|
||||
export function isInternalContentType(contentType?: string): boolean {
|
||||
return typeof contentType !== 'undefined' && matchesMediaType(contentType, INTERNAL_ALL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user