diff --git a/Packages/Pachyderm/Sources/Pachyderm/Client.swift b/Packages/Pachyderm/Sources/Pachyderm/Client.swift index fad780d8..b5ad328b 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Client.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Client.swift @@ -113,6 +113,7 @@ public class Client { var urlRequest = URLRequest(url: url, timeoutInterval: timeoutInterval) urlRequest.httpMethod = request.method.name urlRequest.httpBody = request.body.data + urlRequest.setValue("application/json", forHTTPHeaderField: "Accept") for (name, value) in request.headers { urlRequest.setValue(value, forHTTPHeaderField: name) } diff --git a/Packages/Pachyderm/Sources/Pachyderm/Model/MastodonError.swift b/Packages/Pachyderm/Sources/Pachyderm/Model/MastodonError.swift index 78e99041..430115a4 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Model/MastodonError.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Model/MastodonError.swift @@ -11,7 +11,20 @@ import Foundation struct MastodonError: Decodable, CustomStringConvertible { var description: String + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + if let error = try container.decodeIfPresent(String.self, forKey: .error) { + self.description = error + } else if let message = try container.decodeIfPresent(String.self, forKey: .message) { + self.description = message + } else { + throw DecodingError.keyNotFound(CodingKeys.error, .init(codingPath: container.codingPath, debugDescription: "Missing error or message key")) + } + } + private enum CodingKeys: String, CodingKey { - case description = "error" + case error + // used by pixelfed + case message } }