Skip to content

Commit

Permalink
Rearrange code and polish error message
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqi96 committed Nov 21, 2024
1 parent 99d2240 commit a897682
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions components/log-viewer-webui/server/src/routes/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ import {EXTRACT_JOB_TYPES} from "../DbManager.js";
const routes = async (fastify, options) => {
fastify.post("/query/extract-stream", async (req, resp) => {
const {extractJobType, logEventIdx, streamId} = req.body;
const sanitizedLogEventIdx = Number(logEventIdx);

if (false === EXTRACT_JOB_TYPES.includes(extractJobType)) {
resp.code(StatusCodes.BAD_REQUEST);
throw new Error("Invalid extractJobType");
throw new Error(`Invalid extractJobType="${extractJobType}".`);
}

if ("string" !== typeof streamId || "" === streamId.trim()) {
if ("string" !== typeof streamId || 0 === streamId.trim().length) {
resp.code(StatusCodes.BAD_REQUEST);
throw new Error("streamId must be a non-empty string");
throw new Error("\"streamId\" must be a non-empty string.");
}

const sanitizedLogEventIdx = Number(logEventIdx);
let streamMetadata = await fastify.dbManager.getExtractedStreamFileMetadata(
streamId,
sanitizedLogEventIdx
Expand Down

0 comments on commit a897682

Please sign in to comment.