2

How to limit my stack trace ? In fact, in my json swagger file, I define an object whose field corresponds to an enumeration.

The problem: when I put a string that does not match whith my enumeration. The server response give too much information. I want to delete or limit my stack trace response. How do it ?

My yaml swagger:

{
    "name": "sort",
    "in": "query",
    "description": "The type of sort we want",
    "required": false,
    "type": "string",
    "enum": [ "ASC", "DESC" ] 
}

My http response when I send a Http get with sort=abcd

Error: Parameter (sort) is not an allowable value (ASC, DESC): abcd
            
   at throwErrorWithCode (/usr/src/app/node_modules/swagger-tools/lib/validators.js:116:13)
   at module.exports.validateEnum (/usr/src/app/node_modules/swagger-tools/lib/validators.js:248:5)
   at Object.module.exports.validateSchemaConstraints (/usr/src/app/node_modules/swagger-tools/lib/validators.js:629:5)
   at validateValue (/usr/src/app/node_modules/swagger-tools/middleware/swagger-validator.js:119:16)
   at /usr/src/app/node_modules/swagger-tools/middleware/swagger-validator.js:379:21
   at /usr/src/app/node_modules/async/dist/async.js:1135:9
   at eachOfArrayLike (/usr/src/app/node_modules/async/dist/async.js:1069:9)
   at eachOf (/usr/src/app/node_modules/async/dist/async.js:1117:5)
   at _asyncMap (/usr/src/app/node_modules/async/dist/async.js:1133:5)
   at Object.map (/usr/src/app/node_modules/async/dist/async.js:1122:16)

I use a server node js.

Maybe i have to configure my package.json ???

"scripts": {
      "prestart": "npm install",
      "start": "node index.js",
      "test": "jest --coverage"
 },
marcolz
  • 2,880
  • 2
  • 23
  • 28
Amir Amir
  • 21
  • 1
  • **This topic resolve my problem:** https://stackoverflow.com/questions/38647242/swagger-tools-error-handler-middleware-not-catching-errors – Amir Amir Nov 29 '18 at 10:14
  • Does this answer your question? [More than 10 lines in a node.js stack error?](https://stackoverflow.com/questions/7697038/more-than-10-lines-in-a-node-js-stack-error) – radrow Jan 13 '21 at 09:02

1 Answers1

2

You can try setting in your code Error.stackTraceLimit = 10; or any number of lines that you want.

marcolz
  • 2,880
  • 2
  • 23
  • 28
  • it change nothing because i use a swaggerTools and the stackTrace come from the swagger not from my code. – Amir Amir Nov 16 '18 at 16:08
  • Yes, you can, you can put that in the initialization in your `index.js`. – marcolz Dec 03 '19 at 15:44
  • Marcoiz solution worked beautifully for me. For those looking to surpress output of stacktrace entirely for security reasons, wrapping Error.stackTraceLimit = 0 within the production-only switch worked beautifully for me within the index.js of my Swagger-Tools. Now I can send errors / 403s thru the Swagger callback() without giving away any path information. Beautiful! Thank you! – Sean Halls Mar 29 '20 at 00:21