Skip to content

Commit 59d3e52

Browse files
author
ivan.kishchenko
committed
Fix empty host name resolving
1 parent 21dc88e commit 59d3e52

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Sources/AsposeWordsCloud/Api/Configuration.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ public class Configuration : Codable {
7575
}
7676

7777
// Returns URL to Aspose Cloud API with remote API version
78-
public func getApiRootUrl() -> URL {
79-
return URL(string: self.getBaseUrl())!.appendingPathComponent(self.getApiVersion());
78+
public func getApiRootUrl() throws -> URL {
79+
let url = URL(string: self.getBaseUrl());
80+
if (url == nil) {
81+
throw WordsApiError.badHostAddress(hostName: self.getBaseUrl());
82+
}
83+
84+
return url!.appendingPathComponent(self.getApiVersion());
8085
}
8186

8287
// Returns SDK name for using in statistics headers

Sources/AsposeWordsCloud/Api/WordsApiError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum WordsApiError : LocalizedError {
3131
case requestError(errorCode: Int, message: String?)
3232
case requiredArgumentError(argumentName: String)
3333
case invalidTypeSerialization(typeName: String)
34+
case badHostAddress(hostName: String)
3435

3536
public var errorDescription: String? {
3637
switch self {
@@ -40,6 +41,8 @@ public enum WordsApiError : LocalizedError {
4041
return "Required argument \(argumentName) not present.";
4142
case let .invalidTypeSerialization(typeName):
4243
return "Failed to serialize type '\(typeName)'.";
44+
case let .badHostAddress(hostName):
45+
return "Unable to resolve hostname address '\(hostName)' as url.";
4346
}
4447
}
4548
}

0 commit comments

Comments
 (0)