Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra logs for manifest handler #361

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-fishes-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@saleor/app-sdk": patch
---

Added additional debug logs for createManifestHandler utility. Now app with DEBUG env variable will print extra messagess helpful with broken app installations
27 changes: 21 additions & 6 deletions src/handlers/next/create-manifest-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextApiHandler, NextApiRequest } from "next";

import { createDebug } from "../../debug";
import { getBaseUrl, getSaleorHeaders } from "../../headers";
import { AppManifest } from "../../types";

Expand All @@ -12,6 +13,8 @@ export type CreateManifestHandlerOptions = {
}): AppManifest | Promise<AppManifest>;
};

const debug = createDebug("create-manifest-handler");

/**
* Creates API handler for Next.js. Helps with Manifest creation, hides
* implementation details if possible
Expand All @@ -23,11 +26,23 @@ export const createManifestHandler =
const { schemaVersion } = getSaleorHeaders(request.headers);
const baseURL = getBaseUrl(request.headers);

const manifest = await options.manifestFactory({
appBaseUrl: baseURL,
request,
schemaVersion,
});
debug("Received request with schema version \"%s\" and base URL \"%s\"", schemaVersion, baseURL);

try {
const manifest = await options.manifestFactory({
appBaseUrl: baseURL,
request,
schemaVersion,
});

debug("Executed manifest file");

return response.status(200).json(manifest);
} catch (e) {
debug("Error while resolving manifest: %O", e);

return response.status(200).json(manifest);
return response.status(500).json({
message: "Error resolving manifest file",
});
}
};