netlify-cli 9.15.0 → 9.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
- "version": "9.15.0",
3
+ "version": "9.16.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "netlify-cli",
9
- "version": "9.15.0",
9
+ "version": "9.16.0",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {
@@ -15,7 +15,7 @@
15
15
  "@netlify/framework-info": "^9.0.2",
16
16
  "@netlify/local-functions-proxy": "^1.1.1",
17
17
  "@netlify/plugin-edge-handlers": "^3.0.7",
18
- "@netlify/plugins-list": "^6.17.0",
18
+ "@netlify/plugins-list": "^6.18.1",
19
19
  "@netlify/routing-local-proxy": "^0.34.1",
20
20
  "@netlify/zip-it-and-ship-it": "^5.9.0",
21
21
  "@octokit/rest": "^18.0.0",
@@ -4317,9 +4317,9 @@
4317
4317
  }
4318
4318
  },
4319
4319
  "node_modules/@netlify/plugins-list": {
4320
- "version": "6.17.0",
4321
- "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.17.0.tgz",
4322
- "integrity": "sha512-XQMijnVOxbZwkOeSzUZ8Hwon8WIv9uka5R6+mjJs25lcFiTscA8HqHWjhSHf2xPSrcKopJm4BNJZja5YHV3NQg==",
4320
+ "version": "6.18.1",
4321
+ "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.18.1.tgz",
4322
+ "integrity": "sha512-4aAF+lpoBYOIVMuTxge2YNjNKdMxnsV1equq0VtknBW6EGJ9yFiTPyL0NU0MXDWTWk7dNu8tS5+Uw7LN7+sgcg==",
4323
4323
  "engines": {
4324
4324
  "node": "^12.20.0 || ^14.14.0 || >=16.0.0"
4325
4325
  }
@@ -27260,9 +27260,9 @@
27260
27260
  }
27261
27261
  },
27262
27262
  "@netlify/plugins-list": {
27263
- "version": "6.17.0",
27264
- "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.17.0.tgz",
27265
- "integrity": "sha512-XQMijnVOxbZwkOeSzUZ8Hwon8WIv9uka5R6+mjJs25lcFiTscA8HqHWjhSHf2xPSrcKopJm4BNJZja5YHV3NQg=="
27263
+ "version": "6.18.1",
27264
+ "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.18.1.tgz",
27265
+ "integrity": "sha512-4aAF+lpoBYOIVMuTxge2YNjNKdMxnsV1equq0VtknBW6EGJ9yFiTPyL0NU0MXDWTWk7dNu8tS5+Uw7LN7+sgcg=="
27266
27266
  },
27267
27267
  "@netlify/routing-local-proxy": {
27268
27268
  "version": "0.34.1",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
3
  "description": "Netlify command line tool",
4
- "version": "9.15.0",
4
+ "version": "9.16.0",
5
5
  "author": "Netlify Inc.",
6
6
  "contributors": [
7
7
  "Abraham Schilling <AbrahamSchilling@gmail.com> (https://gitlab.com/n4bb12)",
@@ -48,7 +48,7 @@
48
48
  "Gergely Nemeth (https://twitter.com/nthgergo)",
49
49
  "HonkingGoose",
50
50
  "Ian Martorell <ianmartorell@gmail.com>",
51
- "Ibrahima",
51
+ "Ibrahima G. Coulibaly",
52
52
  "Jackie Macharia (wangoimacharia.dev)",
53
53
  "Jacob Schatz",
54
54
  "Jake Jarvis <jake@jarv.is> (https://twitter.com/jakejarvis)",
@@ -210,7 +210,7 @@
210
210
  "@netlify/framework-info": "^9.0.2",
211
211
  "@netlify/local-functions-proxy": "^1.1.1",
212
212
  "@netlify/plugin-edge-handlers": "^3.0.7",
213
- "@netlify/plugins-list": "^6.17.0",
213
+ "@netlify/plugins-list": "^6.18.1",
214
214
  "@netlify/routing-local-proxy": "^0.34.1",
215
215
  "@netlify/zip-it-and-ship-it": "^5.9.0",
216
216
  "@octokit/rest": "^18.0.0",
@@ -161,7 +161,7 @@ const createHandler = function (options) {
161
161
  return
162
162
  }
163
163
 
164
- handleSynchronousFunction(error, result, response)
164
+ handleSynchronousFunction(error, result, request, response)
165
165
  }
166
166
  }
167
167
  }
@@ -1,5 +1,7 @@
1
1
  // @ts-check
2
2
  const { Buffer } = require('buffer')
3
+ const { readFile } = require('fs').promises
4
+ const { join } = require('path')
3
5
 
4
6
  const { NETLIFYDEVERR } = require('../../utils')
5
7
 
@@ -15,15 +17,15 @@ const addHeaders = (headers, response) => {
15
17
  })
16
18
  }
17
19
 
18
- const handleSynchronousFunction = function (err, result, response) {
20
+ const handleSynchronousFunction = function (err, result, request, response) {
19
21
  if (err) {
20
- return handleErr(err, response)
22
+ return handleErr(err, request, response)
21
23
  }
22
24
 
23
25
  const { error } = validateLambdaResponse(result)
24
26
  if (error) {
25
27
  console.log(`${NETLIFYDEVERR} ${error}`)
26
- return handleErr(error, response)
28
+ return handleErr(error, request, response)
27
29
  }
28
30
 
29
31
  response.statusCode = result.statusCode
@@ -36,14 +38,36 @@ const handleSynchronousFunction = function (err, result, response) {
36
38
  response.end()
37
39
  }
38
40
 
39
- const formatLambdaLocalError = (err) => `${err.errorType}: ${err.errorMessage}\n ${err.stackTrace.join('\n ')}`
41
+ const formatLambdaLocalError = (err, acceptsHtml) =>
42
+ acceptsHtml
43
+ ? JSON.stringify({
44
+ errorType: err.errorType,
45
+ errorMessage: err.errorMessage,
46
+ trace: err.stackTrace,
47
+ })
48
+ : `${err.errorType}: ${err.errorMessage}\n ${err.stackTrace.join('\n ')}`
40
49
 
41
- const handleErr = function (err, response) {
50
+ let errorTemplateFile
51
+
52
+ const renderErrorTemplate = async (errString) => {
53
+ const regexPattern = /<!--@ERROR-DETAILS-->/g
54
+ errorTemplateFile = errorTemplateFile || (await readFile(join(__dirname, './templates/function-error.html'), 'utf-8'))
55
+
56
+ return errorTemplateFile.replace(regexPattern, errString)
57
+ }
58
+
59
+ const processRenderedResponse = async (err, request) => {
60
+ const acceptsHtml = request.headers && request.headers.accept && request.headers.accept.includes('text/html')
61
+ const errorString = typeof err === 'string' ? err : formatLambdaLocalError(err, acceptsHtml)
62
+
63
+ return acceptsHtml ? await renderErrorTemplate(errorString) : errorString
64
+ }
65
+
66
+ const handleErr = async (err, request, response) => {
42
67
  detectAwsSdkError({ err })
43
68
 
44
69
  response.statusCode = 500
45
- const errorString = typeof err === 'string' ? err : formatLambdaLocalError(err)
46
- response.end(errorString)
70
+ response.end(await processRenderedResponse(err, request))
47
71
  }
48
72
 
49
73
  const validateLambdaResponse = (lambdaResponse) => {