mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Create ErrorHandler to convert errors to Representations
This commit is contained in:
@@ -8,3 +8,4 @@ export const APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlenco
|
||||
// Internal content types (not exposed over HTTP)
|
||||
export const INTERNAL_ALL = 'internal/*';
|
||||
export const INTERNAL_QUADS = 'internal/quads';
|
||||
export const INTERNAL_ERROR = 'internal/error';
|
||||
|
||||
@@ -75,16 +75,17 @@ export const AUTH = createUriAndTermNamespace('urn:solid:auth:',
|
||||
);
|
||||
|
||||
export const DC = createUriAndTermNamespace('http://purl.org/dc/terms/',
|
||||
'description',
|
||||
'modified',
|
||||
'title',
|
||||
);
|
||||
|
||||
export const FOAF = createUriAndTermNamespace('http://xmlns.com/foaf/0.1/',
|
||||
'Agent',
|
||||
);
|
||||
|
||||
export const HTTP = createUriAndTermNamespace('urn:solid:http:',
|
||||
'location',
|
||||
'slug',
|
||||
export const HTTP = createUriAndTermNamespace('http://www.w3.org/2011/http#',
|
||||
'statusCodeNumber',
|
||||
);
|
||||
|
||||
export const LDP = createUriAndTermNamespace('http://www.w3.org/ns/ldp#',
|
||||
@@ -112,6 +113,21 @@ export const RDF = createUriAndTermNamespace('http://www.w3.org/1999/02/22-rdf-s
|
||||
'type',
|
||||
);
|
||||
|
||||
export const SOLID = createUriAndTermNamespace('http://www.w3.org/ns/solid/terms#',
|
||||
'oidcIssuer',
|
||||
'oidcIssuerRegistrationToken',
|
||||
'oidcRegistration',
|
||||
);
|
||||
|
||||
export const SOLID_ERROR = createUriAndTermNamespace('urn:npm:solid:community-server:error:',
|
||||
'stack',
|
||||
);
|
||||
|
||||
export const SOLID_HTTP = createUriAndTermNamespace('urn:npm:solid:community-server:http:',
|
||||
'location',
|
||||
'slug',
|
||||
);
|
||||
|
||||
export const VANN = createUriAndTermNamespace('http://purl.org/vocab/vann/',
|
||||
'preferredNamespacePrefix',
|
||||
);
|
||||
@@ -121,12 +137,6 @@ export const XSD = createUriAndTermNamespace('http://www.w3.org/2001/XMLSchema#'
|
||||
'integer',
|
||||
);
|
||||
|
||||
export const SOLID = createUriAndTermNamespace('http://www.w3.org/ns/solid/terms#',
|
||||
'oidcIssuer',
|
||||
'oidcIssuerRegistrationToken',
|
||||
'oidcRegistration',
|
||||
);
|
||||
|
||||
// Alias for commonly used types
|
||||
export const CONTENT_TYPE = MA.format;
|
||||
export const CONTENT_TYPE_TERM = MA.terms.format;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { types } from 'util';
|
||||
import { HttpError } from './HttpError';
|
||||
|
||||
/**
|
||||
* Checks if the input is an {@link Error}.
|
||||
@@ -6,3 +7,20 @@ import { types } from 'util';
|
||||
export function isNativeError(error: any): error is Error {
|
||||
return types.isNativeError(error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the input is a native error.
|
||||
* If not the input will be re-thrown.
|
||||
*/
|
||||
export function assertNativeError(error: any): asserts error is Error {
|
||||
if (!isNativeError(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP status code corresponding to the error.
|
||||
*/
|
||||
export function getStatusCode(error: Error): number {
|
||||
return HttpError.isInstance(error) ? error.statusCode : 500;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user