From 7dcbb57b39a58dd5c208c40665383de0934e1ce7 Mon Sep 17 00:00:00 2001 From: Alexander Eichhorn Date: Wed, 9 Nov 2022 16:33:36 +0100 Subject: [PATCH] added user facing error description for some cases in YouTubeKitError --- Sources/YouTubeKit/Errors.swift | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Sources/YouTubeKit/Errors.swift b/Sources/YouTubeKit/Errors.swift index 875d7ca..35806cb 100644 --- a/Sources/YouTubeKit/Errors.swift +++ b/Sources/YouTubeKit/Errors.swift @@ -7,7 +7,7 @@ import Foundation -public enum YouTubeKitError: Error { +public enum YouTubeKitError: String, Error { case maxRetriesExceeded case htmlParseError case extractError @@ -20,3 +20,28 @@ public enum YouTubeKitError: Error { case membersOnly case videoRegionBlocked } + +extension YouTubeKitError: LocalizedError { + + public var errorDescription: String? { + switch self { + case .videoUnavailable: + return NSLocalizedString("Video unavailable", comment: "") + + case .videoAgeRestricted: + return NSLocalizedString("Video age restricted", comment: "") + + case .liveStreamError: + return NSLocalizedString("Can't extract video from livestream", comment: "") + + case .videoPrivate: + return NSLocalizedString("Video is private", comment: "") + + case .membersOnly: + return NSLocalizedString("Video is members only", comment: "") + + default: return nil + } + } + +}