Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Jul 27, 2024
1 parent f1710f7 commit 0ecbf1f
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Examples/FileBrowser/FileBrowser (macOS)/AuthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ServiceAuthManager: AuthManager {
authWindowController.window?.orderOut(nil)
} catch {
await MainActor.run {
if let error = error as? ErrorResponse, error.header.status == ErrorCodes.logonFailure {
if let error = error as? ErrorResponse, NTStatus(error.header.status) == .logonFailure {
authWindowController.window?.performSelector(
onMainThread: NSSelectorFromString("_shake"),
with: nil,
Expand Down Expand Up @@ -175,7 +175,7 @@ class ServerAuthManager: AuthManager {
authWindowController.window?.orderOut(nil)
} catch {
await MainActor.run {
if let error = error as? ErrorResponse, error.header.status == ErrorCodes.logonFailure {
if let error = error as? ErrorResponse, NTStatus(error.header.status) == .logonFailure {
authWindowController.window?.performSelector(
onMainThread: NSSelectorFromString("_shake"),
with: nil,
Expand Down
4 changes: 2 additions & 2 deletions Examples/FileBrowser/FileBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kishikawakatsumi/SMBClient.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.1.0;
branch = main;
kind = branch;
};
};
145299EA2C3AC745003B035C /* XCRemoteSwiftPackageReference "FlyingFox" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/kishikawakatsumi/SMBClient.git",
"state" : {
"revision" : "870ac07875d41249541a5cfc4ccd5ac8dc0a30ac",
"version" : "0.1.0"
"branch" : "main",
"revision" : "f1710f78e9ed3a7f4de60c29f28294f62aa95f8d"
}
}
],
Expand Down
89 changes: 89 additions & 0 deletions Sources/SMBClient/Messages/ErrorResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,95 @@ extension ErrorResponse: CustomStringConvertible {

extension ErrorResponse: LocalizedError {
public var errorDescription: String? {
switch NTStatus(header.status) {
case .success:
return "Success"
case .pending:
return "Pending"
case .invalidSMB:
return "Invalid SMB"
case .smbBadTid:
return "Bad TID"
case .smbBadCommand:
return "Bad Command"
case .smbBadUID:
return "Bad UID"
case .smbUseStandard:
return "Use Standard"
case .bufferOverflow:
return "Buffer Overflow"
case .noMoreFiles:
return "No More Files"
case .stoppedOnSymlink:
return "Stopped on Symlink"
case .notImplemented:
return "Not Implemented"
case .invalidInfoClass:
return "Invalid Info Class"
case .invalidParameter:
return "Invalid Parameter"
case .noSuchDevice:
return "No Such Device"
case .noSuchFile:
return "No Such File"
case .invalidDeviceRequest:
return "Invalid Device Request"
case .endOfFile:
return "End of File"
case .moreProcessingRequired:
return "More Processing Required"
case .accessDenied:
return "Access Denied"
case .bufferTooSmall:
return "Buffer Too Small"
case .objectNameInvalid:
return "Object Name Invalid"
case .objectNameNotFound:
return "Object Name Not Found"
case .objectNameCollision:
return "Object Name Collision"
case .sharingViolation:
return "Sharing Violation"
case .deletePending:
return "Delete Pending"
case .objectPathNotFound:
return "Object Path Not Found"
case .logonFailure:
return "Logon Failure"
case .badImpersonationLevel:
return "Bad Impersonation Level"
case .ioTimeout:
return "IO Timeout"
case .fileIsADirectory:
return "File is a Directory"
case .notSupported:
return "Not Supported"
case .networkNameDeleted:
return "Network Name Deleted"
case .badNetworkName:
return "Bad Network Name"
case .notADirectory:
return "Not a Directory"
case .fileClosed:
return "File Closed"
case .userSessionDeleted:
return "User Session Deleted"
case .connectionRefused:
return "Connection Refused"
case .networkSessionExpired:
return "Network Session Expired"
case .smbTooManyUIDs:
return "Too Many UIDs"
default:
return "Unknown error"
}
}

public var failureReason: String? {
return description
}

public var recoverySuggestion: String? {
return description
}
}

0 comments on commit 0ecbf1f

Please sign in to comment.