summaryrefslogtreecommitdiff
path: root/DomainDig/IPGeolocationService.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-20 15:28:12 -0500
committerChristian Cleberg <[email protected]>2026-04-20 15:28:12 -0500
commitee2520f2c0c2d806fd284c3d6b8a81a3822f5270 (patch)
tree0680550a1071e01546ba074c2f20b1bf5a452238 /DomainDig/IPGeolocationService.swift
parent4e94ee723cd19c964b1cf37792931e0c7c4614f4 (diff)
downloaddomain-dig-ee2520f2c0c2d806fd284c3d6b8a81a3822f5270.tar.gz
domain-dig-ee2520f2c0c2d806fd284c3d6b8a81a3822f5270.tar.bz2
domain-dig-ee2520f2c0c2d806fd284c3d6b8a81a3822f5270.zip
feat(v1.8): improve result structure, history, and consistency
- normalize sections and add summary card - fix resolver usage in reverse DNS - include custom port scans in history/export - standardize error handling - decompose ContentView into smaller views
Diffstat (limited to 'DomainDig/IPGeolocationService.swift')
-rw-r--r--DomainDig/IPGeolocationService.swift19
1 files changed, 12 insertions, 7 deletions
diff --git a/DomainDig/IPGeolocationService.swift b/DomainDig/IPGeolocationService.swift
index 6c60295..809dd28 100644
--- a/DomainDig/IPGeolocationService.swift
+++ b/DomainDig/IPGeolocationService.swift
@@ -1,17 +1,22 @@
import Foundation
struct IPGeolocationService {
- static func lookup(ip: String) async throws -> IPGeolocation {
+ static func lookup(ip: String) async -> ServiceResult<IPGeolocation> {
let url = URL(string: "https://ipapi.co/\(ip)/json/")!
let request = URLRequest(url: url, timeoutInterval: 10)
- let (data, response) = try await URLSession.shared.data(for: request)
+ do {
+ let (data, response) = try await URLSession.shared.data(for: request)
- guard let httpResponse = response as? HTTPURLResponse,
- httpResponse.statusCode == 200 else {
- throw URLError(.badServerResponse)
- }
+ guard let httpResponse = response as? HTTPURLResponse,
+ httpResponse.statusCode == 200 else {
+ return .error(URLError(.badServerResponse).localizedDescription)
+ }
- return try JSONDecoder().decode(IPGeolocation.self, from: data)
+ let geolocation = try JSONDecoder().decode(IPGeolocation.self, from: data)
+ return .success(geolocation)
+ } catch {
+ return .error(error.localizedDescription)
+ }
}
}