From c1a260dc5660a6336fcf5dc8a3d13c2b2074a787 Mon Sep 17 00:00:00 2001 From: Exerra Date: Tue, 14 Jul 2026 21:56:59 +0300 Subject: [PATCH] fix(AppleMusicSource): add authentication verification to connection checks Implemented status code validation for Apple Music authentication and connection checks. The module now throws errors instead of failing silently when the API is unreachable or auth is invalid. --- src/backend/sources/AppleMusicSource.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/backend/sources/AppleMusicSource.ts b/src/backend/sources/AppleMusicSource.ts index 8fc0b3fe..e829f8b6 100644 --- a/src/backend/sources/AppleMusicSource.ts +++ b/src/backend/sources/AppleMusicSource.ts @@ -85,15 +85,32 @@ export default class AppleMusicSource extends AbstractSource { if (this.config.data?.key) { await this.musicKit.auth(); } + + const status = await this.musicKit.testAuth(); + + if (status !== 200) { + throw new Error(`Apple Music test auth returned status code ${status}`); + } + return true; } catch (e) { this.logger.error(new Error('Apple Music authentication failed', {cause: e})); - return false; + throw e; } } protected async doCheckConnection(): Promise { - return undefined; + if (this.config.data?.key) { + await this.musicKit.auth(); + } + + const status = await this.musicKit.testAuth(); + + if (status !== 200) { + throw new Error(`Apple Music connection check failed with status ${status}`); + } + + return `Apple Music API is reachable (status ${status})`; } static formatPlayObj(track: Song, options: {newFromSource?: boolean} = {}): PlayObject { -- 2.51.2