Repository navigation
feat: Add ErrorToHtmlConverter using templates - #765
Conversation
| } | ||
|
|
||
| public async handle({ representation }: RepresentationConverterArgs): Promise<Representation> { | ||
| const errors = await arrayifyStream(representation.data); |
There was a problem hiding this comment.
| const errors = await arrayifyStream(representation.data); | |
| // We expect the incoming stream to be an object stream with a single error | |
| const errors = await arrayifyStream(representation.data); |
| const options = { | ||
| name: error.name, | ||
| message: error.message, | ||
| stack: error.stack, | ||
| }; | ||
|
|
||
| const template = await fsPromises.readFile(this.templatePath, 'utf8'); | ||
| const html = this.engine.apply(template, options); |
There was a problem hiding this comment.
| const options = { | |
| name: error.name, | |
| message: error.message, | |
| stack: error.stack, | |
| }; | |
| const template = await fsPromises.readFile(this.templatePath, 'utf8'); | |
| const html = this.engine.apply(template, options); | |
| // Render the HTML template | |
| const { name, message, stack } = error; | |
| const variables = { name, message, stack }; | |
| const template = await fsPromises.readFile(this.templatePath, 'utf8'); | |
| const html = this.engine.apply(template, variables); |
There was a problem hiding this comment.
const { name, message, stack } = error; doesn't work unfortunately, it doesn't catch the stack field due to how errors are constructed.
Edit: nvm, I was thinking of an issue when passing the error object directly as a parameter to the templating engine.
| /** | ||
| * Converts an Error to an HTML presentation by filling in the provided template. | ||
| */ | ||
| export class ErrorToHtmlConverter extends TypedRepresentationConverter { |
There was a problem hiding this comment.
I just noted that there's nothing HTML-specific in this class, so the engine might be anything, really.
More of an observation; perhaps contentType could be a constructor param and we can do whatever.
There was a problem hiding this comment.
True, I'll change it to ErrorToTemplateConverter
| export const APPLICATION_SPARQL_UPDATE = 'application/sparql-update'; | ||
| export const APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded'; | ||
| export const TEXT_HTML = 'text/html'; | ||
| export const TEXT_TURTLE = 'text/turtle'; |
There was a problem hiding this comment.
There was a problem hiding this comment.
I just changed the order so they're alphabetical
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>{{ name }}</title> |
There was a problem hiding this comment.
| <title>{{ name }}</title> | |
| <meta charset="utf-8"/> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"/> | |
| <title>{{ name }}</title> |
2769f7f to
a5dfe07
Compare
Closes #654.
Will also have to change after #721 is resolved.