Skip to content

Commit

Permalink
Return 404 for missing nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Feb 11, 2025
1 parent 3cc718d commit 90e0b99
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/resolvers/taxonomyResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { IArticleV2DTO } from "@ndla/types-backend/article-api";
import { ISubjectPageDataDTO } from "@ndla/types-backend/frontpage-api";
import { GraphQLError } from "graphql";
import { Node } from "@ndla/types-taxonomy";
import { fetchChildren, fetchLearningpath, fetchNode, fetchNodeByContentUri, queryNodes } from "../api";
import {
Expand Down Expand Up @@ -37,7 +38,9 @@ export const Query = {
if (contextId) {
const nodes = await queryNodes({ contextId, includeContexts: true, filterProgrammes: true }, context);
if (nodes.length === 0) {
throw new Error(`No node found with contextId: ${contextId}`);
throw new GraphQLError(`No node found with contextId: ${contextId}`, {
extensions: { status: 404 },
});
}
const node = nodes[0];
return node ? nodeToTaxonomyEntity(node, context) : undefined;
Expand Down

0 comments on commit 90e0b99

Please sign in to comment.