@@ -24,15 +24,16 @@ let api = new Api({
2424 },
2525 errorMiddleware (request , error ) {
2626 if (error .code === ' InvalidInputRequest' ) {
27- return { statusCode: 400 , body: { errorCode: ' InvalidRequest' , errorId : request . requestContext . requestId , title: error .message .title } }
27+ return { statusCode: 400 , body: { errorCode: ' InvalidRequest' , title: error .message .title } }
2828 }
2929
30- return { statusCode: 500 , body: { title: ' Unexpected error' , errorId : request . requestContext . requestId } };
30+ return { statusCode: 500 , body: { title: ' Unexpected error' } };
3131 }
3232});
3333```
3434
3535``` js
36+ require (' error-object-polyfill' );
3637class ModelValidator {
3738 constructor () {
3839 this .validator = null ;
@@ -43,7 +44,7 @@ class ModelValidator {
4344 const path = require (' path' );
4445 const { OpenApiValidator } = require (' openapi-data-validator' );
4546 const compiledFilePath = path .join (__dirname , ' compiledSpecValidation.json' );
46- return new OpenApiValidator ({ apiSpec: spec, compiledFilePath: compiledFilePath, validateRequests : { allowUnknownQueryParameters : false } });
47+ return new OpenApiValidator ({ apiSpec: spec, compiledFilePath: compiledFilePath });
4748 }
4849
4950 async compileValidator () {
@@ -80,12 +81,10 @@ class ModelValidator {
8081 try {
8182 await this .validationAsync ;
8283 } catch (error) {
83- const wrapped = Error .create ({ title: ` InvalidRequest: ${ error .message } .` });
84- wrapped .code = ' InvalidInputRequest' ;
85- throw wrapped;
84+ throw Error .create ({ title: ` InvalidRequest: ${ error .message } .` }, ' InvalidInputRequest);
8685 }
8786 }
8887}
8988
9089module.exports = new ModelValidator();
91- ```
90+ ```
0 commit comments