Repository navigation
Use error codes for extensive error descriptions - #795
Conversation
RubenVerborgh
left a comment
There was a problem hiding this comment.
Looks great and the markdown is definitely the way to go.
Just think that the extra HTML step is overkill:
Html is now generated through the new MarkdownToHtmlConverter. This causes us to lose the <title> field with the error name but that seems acceptable.
You can just use HTML tags in your main Markdown file, and then you can also keep the title.
| const message = `Error verifying WebID via Bearer access token: ${(error as Error).message}`; | ||
| this.logger.warn(message); | ||
| throw new BadRequestHttpError(message); | ||
| throw new BadRequestHttpError(message, { cause: error }); |
There was a problem hiding this comment.
Note: we could also just catch (cause: unknown).
| @@ -0,0 +1,13 @@ | |||
| # {{{ name }}} | |||
There was a problem hiding this comment.
So you can actually do <html> and whatever tags you want in markdown. If using kramdown (if that still is a thing), you can then even continue using markdown syntax inside of those elements.
There was a problem hiding this comment.
But then you end up with a html/markdown hybrid which seems less prettier when used in non-html formats. That might also be specific for that library? Since I did look into a way to set something like a title in markdown and there seemed to be no general solution for this. The error descriptions would then also have to contain the entire html file since the title field would need to be in the head part, unless there's a library that takes care of that. At that point it seems to me that we lose a lot of the advantage of having the descriptions only in markdown and we might as well just write them in html directly?
There was a problem hiding this comment.
html/markdown hybrid
HTML tags are subset of the markdown language, so it's technically markdown: https://daringfireball.net/projects/markdown/syntax#html
The title can just be the error code or so?
There was a problem hiding this comment.
Although I'm happy actually with the way things are now.
Idea for title: the markdown could contain a stray <title> tag that is hoisted out. (I do this on my site.)
There was a problem hiding this comment.
Idea for title: the markdown could contain a stray
<title>tag that is hoisted out. (I do this on my site.)
Yea can do that. It just means that the MarkdownToHtmlConverter needs to have some more logic to do this. Technically this could confuse people who for some reason have a markdown file starting with that title tag and did not expect this behaviour but I'm guessing that's not a large group
| {{{ message }}} | ||
| {{/if}} | ||
|
|
||
| {{#if stack}} |
There was a problem hiding this comment.
Let's wrap that in a <pre>.
There was a problem hiding this comment.
The markdown to html conversion library takes care of that due to the code tags.
| @@ -0,0 +1,14 @@ | |||
| <!DOCTYPE html> | |||
There was a problem hiding this comment.
I think we can do without this one, although I do like a consistent template for everything (including IDP etc. at a later stage). Shall we name it main.html or so?
There was a problem hiding this comment.
Main reason for it is to have the title and meta tags (like viewport). Could also be used in the future for linking a css file.
There was a problem hiding this comment.
Yeah that's great indeed; we should strive to use it as a base for all later on.
ba44e5a to
6707137
Compare
6707137 to
c5d1d29
Compare
Closes #673.
I went back and forth several times deciding what the best place would be to do the conversion from code to text. This is what I ended up with.
How it works now is pretty similar to how we handled errors after the last change. The new thing is that the
ErrorToTemplateConverternow also takes the error code into account. It looks in thecodeFolderfor a file matching the exact error code and uses that as a template for the error description if it finds a match. The reason I choose for a folder of templates instead of 1 JSON config with all descriptions in it is because JSON is bad for visualizing newlines.The input parameters for the
ErrorToTemplateConverterhave changed to generate markdown now instead of html. This way the error templates can be written in markdown which seems nicer than having to write them in html. Markdown also seems more reusable if we want to return the error text in a non-html format in the future such as JSON. Html is now generated through the newMarkdownToHtmlConverter. This causes us to lose the<title>field with the error name but that seems acceptable.Several errors also provide a value for the
causefield in the error constructor now. Nothing is done with this yet but it might be useful in the future.