@@ -182,17 +182,38 @@ public class TintedThemesLoader {
182182
183183 private func fetchThemeList( for type: String ) async throws -> [ String ] {
184184 let url = URL ( string: " \( apiURL) / \( type) " ) !
185- let ( data, _) = try await URLSession . shared. data ( from: url)
185+ let ( data, response) = try await URLSession . shared. data ( from: url)
186+
187+ // Check for HTTP errors
188+ if let httpResponse = response as? HTTPURLResponse , httpResponse. statusCode != 200 {
189+ // Try to decode error response
190+ if let errorData = try ? JSONSerialization . jsonObject ( with: data) as? [ String : Any ] ,
191+ let message = errorData [ " message " ] as? String {
192+ throw NSError ( domain: " GitHubAPI " , code: httpResponse. statusCode, userInfo: [ NSLocalizedDescriptionKey: message] )
193+ }
194+ throw NSError ( domain: " GitHubAPI " , code: httpResponse. statusCode, userInfo: [ NSLocalizedDescriptionKey: " HTTP \( httpResponse. statusCode) " ] )
195+ }
186196
187197 struct GitHubFile : Codable {
188198 let name : String
189199 let type : String
190200 }
191201
192- let files = try JSONDecoder ( ) . decode ( [ GitHubFile ] . self, from: data)
193- return files
194- . filter { $0. type == " file " && $0. name. hasSuffix ( " .yaml " ) }
195- . map { String ( $0. name. dropLast ( 5 ) ) } // Remove .yaml extension
202+ // Try to decode as array first, if it fails, check if it's an error response
203+ do {
204+ let files = try JSONDecoder ( ) . decode ( [ GitHubFile ] . self, from: data)
205+ return files
206+ . filter { $0. type == " file " && $0. name. hasSuffix ( " .yaml " ) }
207+ . map { String ( $0. name. dropLast ( 5 ) ) } // Remove .yaml extension
208+ } catch {
209+ // If decoding as array fails, try to decode as error response
210+ if let errorData = try ? JSONSerialization . jsonObject ( with: data) as? [ String : Any ] ,
211+ let message = errorData [ " message " ] as? String {
212+ throw NSError ( domain: " GitHubAPI " , code: - 1 , userInfo: [ NSLocalizedDescriptionKey: " GitHub API Error: \( message) " ] )
213+ }
214+ // Re-throw original decoding error
215+ throw error
216+ }
196217 }
197218
198219 private func loadBase16Theme( name: String ) async -> Base16Theme ? {
0 commit comments