Skip to content

Commit

Permalink
Small modifications in response to pull request conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanbrab committed Jan 25, 2021
1 parent fd3395d commit 34eed9a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
7 changes: 4 additions & 3 deletions lib/converters/html-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ module.exports = class HtmlConverter extends Converter {

/**
* This is a wrapper around convert(), that will render some default HTML if the expected conversion fails.
* Useful in error conditions.
*
* @param htmlInfo - see convert()
* @param data - see convert()
* Call this function in stead of convert(), to complete requests in error conditions.
*
* @param htmlInfo - The information about HTML (path, engine)
* @param data - The JSON data that is used by the engine to substitute variables.
*
* @param message - {string} text to display inside a paragraph of the default HTML, if data cannot be converted as expected
* @param logger - optional logger instance, logs conversion error that causes default HTML rendering
Expand Down
10 changes: 2 additions & 8 deletions lib/handlers/request-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ module.exports = class RequestHandler extends Handler {
}

const handleResponse = this.responseHandler.handle(res, status, 'text/html');

if (!htmlInfo[String(status)]) {
this.logger.warn(`No HTML template is defined for status code ${status}. Sending an empty string instead.`);
handleResponse('');
} else {
const html = await HTMLConverter.convertWithDefault(htmlInfo[String(status)], {}, `Status: ${status}`, this.logger);
handleResponse(html);
}
const html = await HTMLConverter.convertWithDefault(htmlInfo[String(status)], {}, `Status: ${status}`, this.logger);
handleResponse(html);
})
} else {
// No GraphQL query is defined, so we just use the template without data.
Expand Down
2 changes: 1 addition & 1 deletion lib/validators/main-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = class MainValidator {
});

if (hasErrors) {
let err = new Error(output.join('\n'));
const err = new Error(output.join('\n'));
err.type = 'VALIDATION_ERROR';
throw err;
}
Expand Down

0 comments on commit 34eed9a

Please sign in to comment.