Skip to content

Commit 33dfd87

Browse files
committed
fix: remove Bluebird (VF-000) (#67)
**Fixes or implements VF-000** ### Brief description. What is this change? refactors the responsebuilder to not use bluebird this should stop the endless stream of warnings bluebird would produce ![screenshot of warning messages in the logs](https://user-images.githubusercontent.com/7608555/153926817-095dc54d-aad3-41dd-a332-cccccbc45ea6.png) ### Checklist - [ ] this is a breaking change and should publish a new major version - [ ] appropriate tests have been written
1 parent 45047c9 commit 33dfd87

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
}
1313
},
1414
"dependencies": {
15-
"@types/bluebird": "^3.5.33",
1615
"@types/chai": "^4.2.16",
1716
"@types/express": "^4.17.11",
1817
"@types/ioredis": "^4.26.4",
@@ -21,7 +20,6 @@
2120
"@types/sinon": "^10.0.0",
2221
"@voiceflow/logger": "1.6.1",
2322
"@voiceflow/verror": "^1.1.0",
24-
"bluebird": "^3.7.2",
2523
"chai": "^4.3.4",
2624
"dotenv": "^10.0.0",
2725
"express": "^4.17.1",

src/responseBuilder.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import VError from '@voiceflow/verror';
22
import type { AxiosError } from 'axios';
3-
import Promise from 'bluebird';
43
import { NextFunction, Request, Response } from 'express';
54
import * as ExpressValidator from 'express-validator';
65
import { HttpStatus } from 'http-status';
@@ -196,27 +195,27 @@ class ResponseBuilder {
196195
nextCalled = () => next(route);
197196
};
198197

199-
await Promise.try(() => (typeof dataPromise === 'function' ? (dataPromise as any)(req, res, nextCheck) : dataPromise))
200-
.then((data) => {
201-
if (data instanceof Error) {
202-
return ResponseBuilder.errorResponse(data, failureCodeOverride, req);
203-
}
204-
205-
return ResponseBuilder.okResponse(data, successCodeOverride);
206-
})
207-
.catch((err) => ResponseBuilder.errorResponse(err, failureCodeOverride, req))
208-
.then((output) => {
209-
if (res.headersSent) {
210-
return;
211-
}
212-
213-
// eslint-disable-next-line promise/always-return
214-
if (nextCalled) {
215-
nextCalled();
216-
return;
217-
}
198+
let output: ErrorResponse<unknown> | ReturnType<typeof ResponseBuilder['okResponse']>;
199+
200+
try {
201+
const data = await (typeof dataPromise === 'function' ? (dataPromise as any)(req, res, nextCheck) : dataPromise);
202+
203+
output =
204+
data instanceof Error
205+
? ResponseBuilder.errorResponse(data, failureCodeOverride, req)
206+
: ResponseBuilder.okResponse(data, successCodeOverride);
207+
} catch (err) {
208+
output = ResponseBuilder.errorResponse(err, failureCodeOverride, req);
209+
}
210+
211+
if (!res.headersSent) {
212+
if (nextCalled) {
213+
// TypeScript doesn't know that calling nextCheck will define nextCalled as a function
214+
(nextCalled as () => void)();
215+
} else {
218216
res.status(output.code as number).json(output.data);
219-
});
217+
}
218+
}
220219
}) as any;
221220
}
222221
/* eslint-enable no-param-reassign */

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,11 +809,6 @@
809809
dependencies:
810810
axios "*"
811811

812-
"@types/bluebird@^3.5.33":
813-
version "3.5.33"
814-
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.33.tgz#d79c020f283bd50bd76101d7d300313c107325fc"
815-
integrity sha512-ndEo1xvnYeHxm7I/5sF6tBvnsA4Tdi3zj1keRKRs12SP+2ye2A27NDJ1B6PqkfMbGAcT+mqQVqbZRIrhfOp5PQ==
816-
817812
"@types/body-parser@*":
818813
version "1.19.0"
819814
resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.0.tgz#0685b3c47eb3006ffed117cdd55164b61f80538f"

0 commit comments

Comments
 (0)