Error handling

This section is about how to handle Docxtemplater errors.

To be able to see these errors, you need to catch them properly.

try {
    // render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
catch (error) {
    var e = {
        message: error.message,
        stack: error.stack,
    // Handle error

Error Schema

All errors thrown by docxtemplater have the following schema:

    name: One of [GenericError, TemplateError, ScopeParserError, InternalError],
    message: The message of that error,
    properties : {
        explanation: An error that is user friendly (in english), explaining what failed exactly. This error could be shown as is to end users
        id: An identifier of the error that is unique for that type of Error
        ... : The other properties are specific to each type of error.

Error example

If the content of your template is {user {name}, docxtemplater will throw the following error :

try {
catch (e) {
    // All these expressions are true === "TemplateError"
    e.message === "Unclosed tag" === "The tag beginning with '{user ' is unclosed" === "unclosed_tag" === "{user {" === "user "