Skip to content

Commit 95dab65

Browse files
authored
Update async-example.md
1 parent dd750e4 commit 95dab65

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

docs/async-example.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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');
3637
class 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
9089
module.exports = new ModelValidator();
91-
```
90+
```

0 commit comments

Comments
 (0)