Spaces:
Build error
Build error
File size: 1,116 Bytes
d9494a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import { STANDARD_ERROR_MESSAGE } from 'src/engine/api/common/common-query-runners/errors/standard-error-message.constant';
import {
RestInputRequestParserException,
RestInputRequestParserExceptionCode,
} from 'src/engine/api/rest/input-request-parsers/rest-input-request-parser.exception';
import { type Depth } from 'src/engine/api/rest/input-request-parsers/types/depth.type';
import { type AuthenticatedRequest } from 'src/engine/api/rest/types/authenticated-request';
export const parseDepthRestRequest = (request: AuthenticatedRequest): Depth => {
if (!request.query.depth) {
return 0;
}
const depth = +request.query.depth as Depth;
const ALLOWED_DEPTH_VALUES: Depth[] = [0, 1];
if (isNaN(depth) || !ALLOWED_DEPTH_VALUES.includes(depth)) {
throw new RestInputRequestParserException(
`'depth=${
request.query.depth
}' parameter invalid. Allowed values are ${ALLOWED_DEPTH_VALUES.join(
', ',
)}`,
RestInputRequestParserExceptionCode.INVALID_DEPTH_QUERY_PARAM,
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
);
}
return depth;
};
|