mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

The IDP behaviour has been changed to move all error related knowledge to the IdentityProviderHttpHandler instead of managing it in the Interactionhandlers.
33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
import { BasicRepresentation } from '../../ldp/representation/BasicRepresentation';
|
|
import type { Representation } from '../../ldp/representation/Representation';
|
|
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
|
import { INTERNAL_ERROR, INTERNAL_QUADS } from '../../util/ContentTypes';
|
|
import { getSingleItem } from '../../util/StreamUtil';
|
|
import { DC, SOLID_ERROR } from '../../util/Vocabularies';
|
|
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
|
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
|
|
|
/**
|
|
* Converts an error object into quads by creating a triple for each of name/message/stack.
|
|
*/
|
|
export class ErrorToQuadConverter extends TypedRepresentationConverter {
|
|
public constructor() {
|
|
super(INTERNAL_ERROR, INTERNAL_QUADS);
|
|
}
|
|
|
|
public async handle({ identifier, representation }: RepresentationConverterArgs): Promise<Representation> {
|
|
const error = await getSingleItem(representation.data) as Error;
|
|
|
|
// A metadata object makes it easier to add triples due to the utility functions
|
|
const data = new RepresentationMetadata(identifier);
|
|
data.add(DC.terms.title, error.name);
|
|
data.add(DC.terms.description, error.message);
|
|
if (error.stack) {
|
|
data.add(SOLID_ERROR.terms.stack, error.stack);
|
|
}
|
|
|
|
// Update the content-type to quads
|
|
return new BasicRepresentation(data.quads(), representation.metadata, INTERNAL_QUADS, false);
|
|
}
|
|
}
|