Mercurial > public > simoleon
changeset 155:681f2cbe8c7f
Refactor error handling class
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 25 Aug 2021 11:00:21 +0100 |
parents | 8afba86ab8dd |
children | 84137052813d |
files | Simoleon/ErrorHandling.swift Simoleon/Jobs/FileController.swift |
diffstat | 2 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Simoleon/ErrorHandling.swift Wed Aug 25 10:43:12 2021 +0100 +++ b/Simoleon/ErrorHandling.swift Wed Aug 25 11:00:21 2021 +0100 @@ -7,8 +7,10 @@ import Foundation -enum JsonErrors: Error { - case fileMissing - case loadFailed(cause: String) - case parseFailed(cause: String) +class ErrorHandling { + enum Json: Error { + case fileMissing + case loadFailed(cause: String) + case parseFailed(cause: String) + } }
--- a/Simoleon/Jobs/FileController.swift Wed Aug 25 10:43:12 2021 +0100 +++ b/Simoleon/Jobs/FileController.swift Wed Aug 25 11:00:21 2021 +0100 @@ -25,20 +25,20 @@ guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else { - throw JsonErrors.fileMissing + throw ErrorHandling.Json.fileMissing } do { data = try Data(contentsOf: file) } catch { - throw JsonErrors.loadFailed(cause: error.localizedDescription) + throw ErrorHandling.Json.loadFailed(cause: error.localizedDescription) } do { let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) } catch { - throw JsonErrors.parseFailed(cause: error.localizedDescription) + throw ErrorHandling.Json.parseFailed(cause: error.localizedDescription) } } }