forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresError.swift
28 lines (25 loc) · 995 Bytes
/
PostgresError.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Foundation
public enum PostgresError: Error, LocalizedError, CustomStringConvertible {
case `protocol`(String)
case server(PostgresMessage.Error)
case connectionClosed
/// See `LocalizedError`.
public var errorDescription: String? {
return self.description
}
/// See `CustomStringConvertible`.
public var description: String {
let description: String
switch self {
case .protocol(let message): description = "protocol error: \(message)"
case .server(let error):
let severity = error.fields[.severity] ?? "ERROR"
let unique = error.fields[.routine] ?? error.fields[.sqlState] ?? "unknown"
let message = error.fields[.message] ?? "Unknown"
description = "server \(severity.lowercased()): \(message) (\(unique))"
case .connectionClosed:
description = "connection closed"
}
return "NIOPostgres error: \(description)"
}
}