Skip to content

Commit 634743e

Browse files
committed
refactor: refactor json loader
1. Fix access level 2. Use error messages in English 3. Throw error if failed
1 parent 1931a60 commit 634743e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import Foundation
22

3-
public class HolidayJSONLoader {
4-
public static func loadHolidays(fromResource resource: String = "holidays_detailed", bundle: Bundle = .main) -> [String: Holiday] {
3+
class HolidayJSONLoader {
4+
static func loadHolidays(
5+
fromResource resource: String = "holidays_detailed",
6+
bundle: Bundle = .main
7+
) -> [String: Holiday] {
58
guard let url = bundle.url(forResource: resource, withExtension: "json") else {
6-
print("[HolidayJSONLoader] JSONファイルが見つかりません: \(resource).json")
7-
return [:]
9+
fatalError("[HolidayJSONLoader] Unable to find the JSON file: \(resource).json")
810
}
911
guard let data = try? Data(contentsOf: url) else {
10-
print("[HolidayJSONLoader] JSONファイルの読み込みに失敗しました")
11-
return [:]
12+
fatalError("[HolidayJSONLoader] Failed to load the JSON data: \(url)")
1213
}
1314
do {
1415
let holidays = try JSONDecoder().decode([String: Holiday].self, from: data)
1516
return holidays
1617
} catch {
17-
print("[HolidayJSONLoader] JSONのデコードに失敗しました: \(error)")
18-
return [:]
18+
fatalError("[HolidayJSONLoader] Failed to decode the JSON data: \(error)")
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)