Skip to content

Commit

Permalink
extra logs for manifest handler (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkostrowski authored May 20, 2024
1 parent 3bba0f1 commit d24c734
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
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",
});
}
};

0 comments on commit d24c734

Please sign in to comment.