• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supabase-swift / 28956968023

08 Jul 2026 04:01PM UTC coverage: 46.475% (-36.9%) from 83.384%
28956968023

Pull #1093

github

web-flow
Merge 3467cc11d into cda19c62f
Pull Request #1093: refactor(storage): adopt swift-openapi-generator for the HTTP layer

1346 of 9871 new or added lines in 8 files covered. (13.64%)

20 existing lines in 2 files now uncovered.

8729 of 18782 relevant lines covered (46.48%)

18.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.67
/Sources/Storage/StorageError.swift
1
public import Foundation
2
import OpenAPIRuntime
3

4
/// An error returned by the Supabase Storage API.
5
///
6
/// ``StorageError`` is thrown whenever the server responds with a non-2xx status code or when the
7
/// response body contains a recognizable error payload. Inspect ``message`` for a human-readable
8
/// description, and ``statusCode`` for the HTTP status code string returned by the API.
9
///
10
/// ```swift
11
/// do {
12
///   try await storage.from("avatars").download(path: "missing.png")
13
/// } catch let error as StorageError {
14
///   print(error.statusCode ?? "unknown", error.message)
15
/// }
16
/// ```
17
public struct StorageError: Error, Decodable, Sendable {
18
  /// The HTTP status code returned by the API, represented as a string (e.g. `"404"`).
19
  public var statusCode: String?
20

21
  /// A human-readable description of the error.
22
  public var message: String
23

24
  /// A short error identifier string returned by the API, if available.
25
  public var error: String?
26

27
  /// Creates a ``StorageError``.
28
  ///
29
  /// - Parameters:
30
  ///   - statusCode: The HTTP status code string, if known.
31
  ///   - message: A human-readable description of the error.
32
  ///   - error: A short error identifier string, if available.
33
  public init(statusCode: String? = nil, message: String, error: String? = nil) {
3✔
34
    self.statusCode = statusCode
3✔
35
    self.message = message
3✔
36
    self.error = error
3✔
37
  }
3✔
38
}
39

40
extension StorageError: LocalizedError {
41
  /// A localized description of the error, equal to ``message``.
42
  public var errorDescription: String? {
1✔
43
    message
1✔
44
  }
1✔
45
}
46

47
extension StorageError {
48
  /// A generic placeholder used only when a response is neither a recognized success nor a
49
  /// decodable error shape (should not happen against a spec-conforming server).
NEW
50
  static func unexpectedResponse() -> StorageError {
×
NEW
51
    StorageError(statusCode: nil, message: "Unexpected response from Storage API")
×
NEW
52
  }
×
53

54
  /// Builds a ``StorageError`` from a documented `errorSchema`-shaped generated response body
55
  /// (the `.forbidden` case, which has no separate status code of its own).
NEW
56
  init(decoding errorSchema: Components.Schemas.errorSchema, statusCode: String? = nil) {
×
NEW
57
    self.init(
×
NEW
58
      statusCode: statusCode ?? errorSchema.statusCode,
×
NEW
59
      message: errorSchema.message,
×
NEW
60
      error: errorSchema.error
×
NEW
61
    )
×
NEW
62
  }
×
63

64
  /// Builds a ``StorageError`` from a documented `errorSchema`-shaped generated response body
65
  /// (the `.clientError` case, which carries its own numeric HTTP status code).
66
  init(statusCode: Int, decoding errorSchema: Components.Schemas.errorSchema) {
1✔
67
    self.init(
1✔
68
      statusCode: String(statusCode),
1✔
69
      message: errorSchema.message,
1✔
70
      error: errorSchema.error
1✔
71
    )
1✔
72
  }
1✔
73

74
  /// Builds a ``StorageError`` from an `.undocumented` generated response, decoding the raw body
75
  /// bytes as ``StorageError`` JSON when possible (mirrors the non-OpenAPI fallback in
76
  /// ``StorageApi``'s `executeRequest`), falling back to a generic placeholder otherwise.
77
  init(
78
    statusCode: Int,
79
    undocumented payload: UndocumentedPayload,
80
    decoder: JSONDecoder
NEW
81
  ) async {
×
NEW
82
    if let body = payload.body,
×
NEW
83
      let data = try? await Data(collecting: body, upTo: .max),
×
NEW
84
      let error = try? decoder.decode(StorageError.self, from: data)
×
NEW
85
    {
×
NEW
86
      self = error
×
NEW
87
    } else {
×
NEW
88
      self = StorageError(
×
NEW
89
        statusCode: String(statusCode), message: "Unexpected response from Storage API")
×
NEW
90
    }
×
NEW
91
  }
×
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc