Skip to content

Commit 090eaed

Browse files
committed
fix: resolve PR comments
1 parent 4248ffd commit 090eaed

File tree

4 files changed

+282
-28
lines changed

4 files changed

+282
-28
lines changed

packages/typed-express-router/src/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as PathReporter from 'io-ts/lib/PathReporter';
2+
23
import type {
34
DecodeErrorFormatterFn,
45
EncodeErrorFormatterFn,

packages/typed-express-router/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*/
44

55
import { ApiSpec, HttpRoute, KeyToHttpStatus } from '@api-ts/io-ts-http';
6+
import type { Span } from '@opentelemetry/api';
67
import express from 'express';
78
import * as E from 'fp-ts/Either';
89
import { pipe } from 'fp-ts/pipeable';
10+
911
import {
1012
defaultDecodeErrorFormatter,
1113
defaultEncodeErrorFormatter,
@@ -34,8 +36,6 @@ import {
3436
WrappedRouterOptions,
3537
} from './types';
3638

37-
import type { Span } from '@opentelemetry/api';
38-
3939
export type {
4040
AfterEncodedResponseSentFn,
4141
DecodeErrorFormatterFn,

packages/typed-express-router/test/server.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,27 @@ test('should send a 500 when response type does not match', async () => {
440440
assert.equal(response.original.status, 500);
441441
});
442442

443+
test('should invoke default encode error function when response type does not match', async () => {
444+
const router = createRouter(TestApiSpec);
445+
446+
router.get('hello.world', [
447+
(_req, res) => {
448+
res.sendEncoded(200, { what: 'is this parameter?' } as any);
449+
},
450+
]);
451+
452+
const app = express();
453+
app.use(express.json());
454+
app.use(router);
455+
456+
const server = supertest(app);
457+
const apiClient = buildApiClient(supertestRequestFactory(server), TestApiSpec);
458+
const response = await apiClient['hello.world'].get({ id: '1234' }).decode();
459+
460+
assert.equal(response.original.status, 500);
461+
assert.deepStrictEqual(response.body, {});
462+
});
463+
443464
test('should invoke custom encode error function when response type does not match', async () => {
444465
const router = createRouter(TestApiSpec, {
445466
encodeErrorFormatter: (_err, _req) => {

0 commit comments

Comments
 (0)