Skip to content

Commit cb07e54

Browse files
committed
fix: add 400 response validator to prevent 500 in TEST_MODE
When _internalRouteActionHandler catches errors and returns status 400, the Router's response validation in TEST_MODE requires a matching response validator. Without a 400 validator, it throws 'Missing response validator' which becomes HTTP 500. Also remove unnecessary null check that wasn't in original code.
1 parent 15cdd41 commit cb07e54

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

apps/meteor/app/api/server/v1/stats.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TelemetryEvents, TelemetryMap } from '@rocket.chat/core-services';
22
import type { IStats } from '@rocket.chat/core-typings';
3-
import { ajv, validateUnauthorizedErrorResponse } from '@rocket.chat/rest-typings';
3+
import { ajv, validateBadRequestErrorResponse, validateUnauthorizedErrorResponse } from '@rocket.chat/rest-typings';
44

55
import { getStatistics, getLastStatistics } from '../../../statistics/server';
66
import telemetryEvent from '../../../statistics/server/lib/telemetryEvents';
@@ -33,22 +33,19 @@ API.v1.get(
3333
},
3434
required: ['success'],
3535
}),
36+
400: validateBadRequestErrorResponse,
3637
401: validateUnauthorizedErrorResponse,
3738
},
3839
},
3940
async function action() {
4041
const { refresh = 'false' } = this.queryParams;
4142

42-
const stats = await getLastStatistics({
43-
userId: this.userId,
44-
refresh: refresh === 'true',
45-
});
46-
47-
if (!stats) {
48-
throw new Error('No statistics found');
49-
}
50-
51-
return API.v1.success(stats);
43+
return API.v1.success(
44+
await getLastStatistics({
45+
userId: this.userId,
46+
refresh: refresh === 'true',
47+
}),
48+
);
5249
},
5350
);
5451

@@ -88,6 +85,7 @@ API.v1.get(
8885
},
8986
required: ['statistics', 'count', 'offset', 'total', 'success'],
9087
}),
88+
400: validateBadRequestErrorResponse,
9189
401: validateUnauthorizedErrorResponse,
9290
},
9391
},
@@ -142,6 +140,7 @@ API.v1.post(
142140
required: ['success'],
143141
additionalProperties: false,
144142
}),
143+
400: validateBadRequestErrorResponse,
145144
401: validateUnauthorizedErrorResponse,
146145
},
147146
},

0 commit comments

Comments
 (0)