How to limit the stack trace of my node.js Swagger server?

Viewed 710

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"
 },
1 Answers

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

Related