diff --git a/src/types/zod.gen.ts b/src/types/zod.gen.ts index 5f8a7d0..555fb71 100644 --- a/src/types/zod.gen.ts +++ b/src/types/zod.gen.ts @@ -1,7 +1,7 @@ import { z } from "zod"; -export const apiErrorSchema = z.object({ "status": z.union([z.literal(500), z.literal(504), z.literal(400), z.literal(401), z.literal(403), z.literal(404), z.literal(405)]), "code": z.enum(["bad_database_response", "bad_header", "missing_required_header", "bad_query_input", "database_timeout", "forbidden", "internal_server_error", "method_not_allowed", "route_not_found", "unauthorized"]), "message": z.coerce.string() }); +export const apiErrorSchema = z.object({ "status": z.union([z.literal(500), z.literal(504), z.literal(400), z.literal(401), z.literal(403), z.literal(404), z.literal(405)]), "code": z.enum(["bad_database_response", "bad_header", "missing_required_header", "bad_query_input", "database_timeout", "forbidden", "internal_server_error", "method_not_allowed", "route_not_found", "unauthorized", "not_found_data"]), "message": z.coerce.string() }); export type ApiErrorSchema = z.infer; diff --git a/src/typespec/openapi3.tsp b/src/typespec/openapi3.tsp index 2ed58a6..ccd0f41 100644 --- a/src/typespec/openapi3.tsp +++ b/src/typespec/openapi3.tsp @@ -31,7 +31,8 @@ alias ApiErrorCode = | "internal_server_error" // an unknown error occurred on the backend | "method_not_allowed" // http method is not allowed on this endpoint | "route_not_found" // the requested route was not found - | "unauthorized"; // invalid authorization information given + | "unauthorized" // invalid authorization information given + | "not_found_data"; // no data found for the given query alias ErrorStatusCode = 500 | 504 | 400 | 401 | 403 | 404 | 405; diff --git a/src/usage.ts b/src/usage.ts index 731d9c9..63e1458 100644 --- a/src/usage.ts +++ b/src/usage.ts @@ -45,7 +45,11 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use if (query_params.offset) query.push("OFFSET {offset: int}"); try { - return ctx.json(await makeQuery(query.join(" "), { ...query_params })); + const result = await makeQuery(query.join(" "), { ...query_params }); + if (result.data.length === 0) { + return APIErrorResponse(ctx, 404, "not_found_data", `No data found for ${table_name}`); + } + return ctx.json(result); } catch (err) { return APIErrorResponse(ctx, 500, "bad_database_response", err); } diff --git a/static/@typespec/openapi3/openapi.json b/static/@typespec/openapi3/openapi.json index 38569c6..c3f6633 100644 --- a/static/@typespec/openapi3/openapi.json +++ b/static/@typespec/openapi3/openapi.json @@ -2359,7 +2359,8 @@ "internal_server_error", "method_not_allowed", "route_not_found", - "unauthorized" + "unauthorized", + "not_found_data" ] }, "message": {