Skip to content

Commit

Permalink
feat: remove redundant function error template and clean old one
Browse files Browse the repository at this point in the history
  • Loading branch information
khendrikse committed Sep 26, 2022
1 parent 84884f1 commit 906fe6d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 347 deletions.
4 changes: 3 additions & 1 deletion src/lib/functions/synchronous.js
Expand Up @@ -50,7 +50,9 @@ const processRenderedResponse = async (err, request) => {
const acceptsHtml = request.headers && request.headers.accept && request.headers.accept.includes('text/html')
const errorString = typeof err === 'string' ? err : formatLambdaLocalError(err, acceptsHtml)

return acceptsHtml ? await renderErrorTemplate(errorString, './templates/function-error.html') : errorString
return acceptsHtml
? await renderErrorTemplate(errorString, './templates/function-error.html', 'function')
: errorString
}

const handleErr = async (err, request, response) => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/render-error-remplate.js
Expand Up @@ -3,12 +3,12 @@ const { join } = require('path')

let errorTemplateFile

const renderErrorTemplate = async (errString, templatePath) => {
const regexPattern = /<!--@ERROR-DETAILS-->/g

const renderErrorTemplate = async (errString, templatePath, functionType) => {
const errorDetailsRegex = /<!--@ERROR-DETAILS-->/g
const functionTypeRegex = /<!--@FUNCTION-TYPE-->/g
try {
errorTemplateFile = errorTemplateFile || (await readFile(join(__dirname, templatePath), 'utf-8'))
return errorTemplateFile.replace(regexPattern, errString)
return errorTemplateFile.replace(errorDetailsRegex, errString).replace(functionTypeRegex, functionType)
} catch {
return errString
}
Expand Down
289 changes: 0 additions & 289 deletions src/lib/templates/edge-function-error.html

This file was deleted.

0 comments on commit 906fe6d

Please sign in to comment.