error handling

This commit is contained in:
Max Peintner
2025-01-16 11:08:12 +01:00
parent 596299b6ec
commit fc7045aeb2
2 changed files with 10 additions and 2 deletions

View File

@@ -9,7 +9,15 @@ export async function getInstanceUrl(host: string): Promise<string> {
return process.env.ZITADEL_API_URL || "";
}
const instance = await getInstanceByHost(host);
const instance = await getInstanceByHost(host).catch((error) => {
console.error(`Could not get instance by host ${host}`, error);
return null;
});
if (!instance) {
throw new Error("No instance found");
}
const generatedDomain = instance.domains.find(
(domain) => domain.generated === true,
);

View File

@@ -32,7 +32,7 @@ export async function middleware(request: NextRequest) {
instanceUrl = await getInstanceUrl(host);
} catch (error) {
console.error(
"Could not get instance url, fallback to ZITADEL_API_URL",
`[Middleware]: Could not get instance url of ${host}, fallback to ZITADEL_API_URL ${process.env.ZITADEL_API_URL}`,
error,
);
instanceUrl = process.env.ZITADEL_API_URL;