feat(SW-66, SW-348): search functionality and ui

This commit is contained in:
Simon Emanuelsson
2024-08-28 10:47:57 +02:00
parent b9dbcf7d90
commit af850c90e7
437 changed files with 7663 additions and 9881 deletions
+27 -3
View File
@@ -1,7 +1,8 @@
import "server-only"
import { GraphQLClient } from "graphql-request"
import { ClientError, GraphQLClient } from "graphql-request"
import { Lang } from "@/constants/languages"
import { env } from "@/env/server"
import type { DocumentNode } from "graphql"
@@ -74,8 +75,31 @@ export async function request<T>(
return { data: response }
} catch (error) {
console.error("Error in graphql request")
console.error(error)
if (error instanceof ClientError) {
if (error.response.errors?.length) {
const failedToFetchItem = error.response.errors.find(
(err) => err.message === "Failed to fetch item"
)
if (
failedToFetchItem &&
failedToFetchItem.extensions?.errors === "Object not found!" &&
failedToFetchItem.path?.find((p) => Lang[p as Lang])
) {
/**
* Because of Contentstacks totally obscure way of implementing
* GraphQL where they throw an error when you are querying for
* a single item that is nullable and doesn't exist. This leads
* to the issue where when we have a page that is missing a published
* version for one language, it throws an error which we have to recover
* from here since it isn't an error.
*/
return { data: error.response.data as T }
}
}
}
// console.error("Error in graphql request")
// console.error(error)
throw new Error("Something went wrong")
}
}