mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Fix figma not working on startup (#481)
* Fix figma startup requests failing * log the ID * fix 404 * Ensure we always send teamId as a string * changelog
This commit is contained in:
parent
23eae91737
commit
e8159579b2
1
changelog.d/481.bugfix
Normal file
1
changelog.d/481.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix Figma service not being able to create new webhooks on startup, causing a crash.
|
@ -41,21 +41,25 @@ export async function ensureFigmaWebhooks(figmaConfig: BridgeConfigFigma, matrix
|
|||||||
let webhookDefinition: FigmaWebhookDefinition|undefined;
|
let webhookDefinition: FigmaWebhookDefinition|undefined;
|
||||||
if (webhookId) {
|
if (webhookId) {
|
||||||
try {
|
try {
|
||||||
webhookDefinition = (await client.client.get(`v2/webhooks/${webhookId}`, axiosConfig)).data;
|
webhookDefinition = (await client.client.get(`webhooks/${webhookId}`, axiosConfig)).data;
|
||||||
log.info(`Found existing hook for Figma instance ${instanceName} ${webhookId}`);
|
log.info(`Found existing hook for Figma instance ${instanceName} ${webhookId}`);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
const axiosErr = ex as AxiosError;
|
const axiosErr = ex as AxiosError;
|
||||||
if (axiosErr.isAxiosError) {
|
if (axiosErr.response?.status !== 404) {
|
||||||
log.error(`Failed to update webhook: ${axiosErr.code} ${axiosErr.response?.data?.message ?? ""}`)
|
// Missing webhook, probably not found.
|
||||||
|
if (axiosErr.isAxiosError) {
|
||||||
|
log.error(`Failed to update webhook: ${axiosErr.response?.status} ${axiosErr.response?.data?.message ?? ""}`)
|
||||||
|
}
|
||||||
|
throw Error(`Failed to verify Figma webhooks for ${instanceName}: ${ex.message}`);
|
||||||
}
|
}
|
||||||
throw Error(`Failed to verify Figma webhooks for ${instanceName}: ${ex.message}`);
|
log.warn(`Previous webhook ID ${webhookId} stored but API returned not found, creating new one.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (webhookDefinition) {
|
if (webhookDefinition) {
|
||||||
if (webhookDefinition.endpoint !== publicUrl || webhookDefinition.passcode !== passcode) {
|
if (webhookDefinition.endpoint !== publicUrl || webhookDefinition.passcode !== passcode) {
|
||||||
log.info(`Existing hook ${webhookId} for ${instanceName} has stale endpoint or passcode, updating`);
|
log.info(`Existing hook ${webhookId} for ${instanceName} has stale endpoint or passcode, updating`);
|
||||||
try {
|
try {
|
||||||
await client.client.put(`v2/webhooks/${webhookId}`, {
|
await client.client.put(`webhooks/${webhookId}`, {
|
||||||
passcode,
|
passcode,
|
||||||
endpoint: publicUrl,
|
endpoint: publicUrl,
|
||||||
}, axiosConfig);
|
}, axiosConfig);
|
||||||
@ -70,12 +74,12 @@ export async function ensureFigmaWebhooks(figmaConfig: BridgeConfigFigma, matrix
|
|||||||
} else {
|
} else {
|
||||||
log.info(`No webhook defined for instance ${instanceName}, creating`);
|
log.info(`No webhook defined for instance ${instanceName}, creating`);
|
||||||
try {
|
try {
|
||||||
const res = await client.client.post(`v2/webhooks`, {
|
const res = await client.client.post(`webhooks`, {
|
||||||
passcode,
|
passcode,
|
||||||
endpoint: publicUrl,
|
endpoint: publicUrl,
|
||||||
description: 'matrix-hookshot',
|
description: 'matrix-hookshot',
|
||||||
event_type: 'FILE_COMMENT',
|
event_type: 'FILE_COMMENT',
|
||||||
team_id: teamId,
|
team_id: teamId.toString(),
|
||||||
}, axiosConfig);
|
}, axiosConfig);
|
||||||
webhookDefinition = res.data as FigmaWebhookDefinition;
|
webhookDefinition = res.data as FigmaWebhookDefinition;
|
||||||
await matrixClient.setAccountData(accountDataKey, {webhookId: webhookDefinition.id});
|
await matrixClient.setAccountData(accountDataKey, {webhookId: webhookDefinition.id});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user