@solid/community-server
Version:
Community Solid Server: an open and modular implementation of the Solid specifications
36 lines (35 loc) • 1.76 kB
TypeScript
import { RepresentationMetadata } from '../../http/representation/RepresentationMetadata';
import { HttpError } from './HttpError';
import Dict = NodeJS.Dict;
/**
* Adds the given terms to error metadata.
* The keys will be converted to predicates by prepending them with the `SOLID_ERROR_TERM` namespace.
* The values will become literals.
*
* @param terms - Terms to add to the metadata.
* @param metadata - Metadata to add the terms to. A new metadata object will be created if this is undefined.
*/
export declare function errorTermsToMetadata(terms: Dict<string>, metadata?: RepresentationMetadata): RepresentationMetadata;
/**
* Extracts all the error metadata terms and converts them to a simple object.
* All predicates in the `SOLID_ERROR_TERM` namespace will be found.
* The namespace will be removed from the predicate and the remainder will be used as a key.
* The object literal values will be used as values in the resulting object.
*
* @param metadata - Metadata to extract the terms from.
*/
export declare function extractErrorTerms(metadata: RepresentationMetadata): Dict<string>;
/**
* Converts an error in any shape to an {@link HttpError}.
* For an {@link AggregateError} all the source errors will be combined
* into a single HttpError with a status code that makes sense based on the sources.
*/
export declare function toHttpError(error: unknown): HttpError;
/**
* Combines a list of errors into a single HttpError.
* Status code depends on the input errors. If they all share the same status code that code will be re-used.
* If they are all within the 4xx range, 400 will be used, otherwise 500.
*
* @param errors - Errors to combine.
*/
export declare function createAggregateError(errors: Error[]): HttpError;