Skip to content

Commit

Permalink
fix(middleware): Handle improperly configured requests gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Nov 15, 2024
1 parent 4790efa commit d868c53
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ async function getConfigPromise(context) {
return resolvedValue;
}

// check if useFlyoIntegration is available and configured correctly
if (!useFlyoIntegration()?.config || false) {
console.error("useFlyoIntegration is not available or not configured correctly.");
return null;
}

// Fetch the config and store the resolved value
const value = await useConfigApi().config({
lang: context.currentLocale,
Expand All @@ -25,7 +31,13 @@ export const onRequest = defineMiddleware(async (context, next) => {

context.locals.config = getConfigPromise(context);

const liveEditEnabled = useFlyoIntegration().options.liveEdit;
let liveEditEnabled = false;
try {
// Safely retrieve options from useFlyoIntegration
liveEditEnabled = useFlyoIntegration()?.options?.liveEdit || false;
} catch (error) {
console.error("Error in useFlyoIntegration:", error);
}

if (!liveEditEnabled) {
const response = await next();
Expand Down

0 comments on commit d868c53

Please sign in to comment.