(ctx: DeleteSubscriptionContext)
| 234 | }, |
| 235 | |
| 236 | async deleteSubscription(ctx: DeleteSubscriptionContext): Promise<void> { |
| 237 | try { |
| 238 | const config = getProviderConfig(ctx.webhook) |
| 239 | const apiKey = config.apiKey as string | undefined |
| 240 | const externalId = config.externalId as string | undefined |
| 241 | |
| 242 | if (!apiKey) { |
| 243 | logger.warn( |
| 244 | `[${ctx.requestId}] Missing apiKey for Rootly webhook deletion ${ctx.webhook.id}, skipping cleanup` |
| 245 | ) |
| 246 | if (ctx.strict) throw new Error('Missing Rootly apiKey for webhook deletion') |
| 247 | return |
| 248 | } |
| 249 | |
| 250 | if (!externalId) { |
| 251 | logger.warn( |
| 252 | `[${ctx.requestId}] Missing externalId for Rootly webhook deletion ${ctx.webhook.id}, skipping cleanup` |
| 253 | ) |
| 254 | if (ctx.strict) throw new Error('Missing Rootly externalId for webhook deletion') |
| 255 | return |
| 256 | } |
| 257 | |
| 258 | const response = await fetch(`https://api.rootly.com/v1/webhooks/endpoints/${externalId}`, { |
| 259 | method: 'DELETE', |
| 260 | headers: { |
| 261 | Authorization: `Bearer ${apiKey}`, |
| 262 | Accept: 'application/vnd.api+json', |
| 263 | }, |
| 264 | }) |
| 265 | |
| 266 | if (response.ok || response.status === 404) { |
| 267 | await response.body?.cancel() |
| 268 | logger.info( |
| 269 | `[${ctx.requestId}] Deleted Rootly webhook endpoint ${externalId} (status ${response.status})` |
| 270 | ) |
| 271 | } else { |
| 272 | const responseBody = await response.json().catch(() => ({})) |
| 273 | logger.warn( |
| 274 | `[${ctx.requestId}] Failed to delete Rootly webhook endpoint (non-fatal): ${response.status}`, |
| 275 | { response: responseBody } |
| 276 | ) |
| 277 | if (ctx.strict) { |
| 278 | throw new Error(`Failed to delete Rootly webhook endpoint: ${response.status}`) |
| 279 | } |
| 280 | } |
| 281 | } catch (error) { |
| 282 | logger.warn(`[${ctx.requestId}] Error deleting Rootly webhook (non-fatal)`, error) |
| 283 | if (ctx.strict) throw error |
| 284 | } |
| 285 | }, |
| 286 | } |
nothing calls this directly
no test coverage detected