-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the capability to provide a Codable object to RequestError that will be encoded and sent by the Router as the response body when passed to the completion handler of a codable route.
- Loading branch information
1 parent
0042c1d
commit 6419b27
Showing
4 changed files
with
448 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright IBM Corporation 2018 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
import Foundation | ||
|
||
/** | ||
A set of values representing the format of a response body. | ||
|
||
This struct is intended to be "enum-like" and values should be | ||
accessed via the public static stored properties. | ||
|
||
- Note: An enum was not used here because currently enums are | ||
always exhaustive. This means adding a case to an enum | ||
is a breaking change. In order to keep such additions | ||
non-breaking we have used an "enum-like" struct instead. | ||
This means code using `BodyFormat` should always handle | ||
unrecognised `BodyFormat` values (eg in a default case | ||
of a switch). `UnsupportedBodyFormatError` may be used | ||
in this situation. | ||
|
||
### Usage Example: ### | ||
```` | ||
let format = BodyFormat.json | ||
```` | ||
*/ | ||
public struct BodyFormat: Equatable { | ||
public let type: String | ||
|
||
private init(_ type: String) { | ||
self.type = type | ||
} | ||
|
||
public static func == (_ lhs: BodyFormat, _ rhs: BodyFormat) -> Bool { | ||
return lhs.type == rhs.type | ||
} | ||
|
||
public static let json = BodyFormat("application/json") | ||
} | ||
|
||
/** | ||
An error that may be thrown when a particular instance of `BodyFormat` | ||
is not supported | ||
*/ | ||
public struct UnsupportedBodyFormatError: Error { | ||
public let bodyFormat: BodyFormat | ||
public init(_ bodyFormat: BodyFormat) { | ||
self.bodyFormat = bodyFormat | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.