-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace AppleScriptError with QueryError
- Loading branch information
Showing
5 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// QueryError.swift | ||
// Easydict | ||
// | ||
// Created by tisfeng on 2024/9/14. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - QueryError | ||
|
||
@objcMembers | ||
public class QueryError: NSError, LocalizedError { | ||
// MARK: Lifecycle | ||
|
||
public init(type: ErrorType, code: Int = -1, message: String) { | ||
self.type = type | ||
self.message = message | ||
let userInfo = [NSLocalizedDescriptionKey: message] | ||
super.init(domain: Bundle.main.bundleIdentifier!, code: code, userInfo: userInfo) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: Public | ||
|
||
public enum ErrorType: String { | ||
case unknown = "Unknown Error" | ||
case api = "API Error" | ||
case parameter = "Parameter Error" | ||
case timeout = "Timeout Error" | ||
case appleScript = "AppleScript Execution Error" | ||
case unsupported = "Unsupported Language" | ||
case missingSecretKey = "Missing Secret Key" | ||
} | ||
|
||
public let type: ErrorType | ||
public var message: String | ||
|
||
public override var localizedDescription: String { | ||
description | ||
} | ||
|
||
public override var description: String { | ||
"\(type.rawValue): \(message)" | ||
} | ||
|
||
public static func error(type: ErrorType, code: Int = -1, message: String) -> QueryError { | ||
QueryError(type: type, code: code, message: message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters