From 74084844f7def572171311f450cb7d3df0da87c4 Mon Sep 17 00:00:00 2001 From: Ondrej Rafaj Date: Wed, 17 Jul 2019 13:56:19 +0100 Subject: [PATCH] initial upload --- .gitignore | 2 ++ LICENSE | 21 +++++++++++++++++++++ Package.resolved | 25 +++++++++++++++++++++++++ Package.swift | 25 +++++++++++++++++++++++++ README.md | 17 +++++++++++++++++ Sources/NIOErrorKit/Exports.swift | 3 +++ Sources/NIOErrorKit/WebError+NIO.swift | 16 ++++++++++++++++ 7 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Package.resolved create mode 100644 Package.swift create mode 100644 README.md create mode 100644 Sources/NIOErrorKit/Exports.swift create mode 100644 Sources/NIOErrorKit/WebError+NIO.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9d0fdc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +.swiftpm diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dfca272 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Einstore + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..83f5f2d --- /dev/null +++ b/Package.resolved @@ -0,0 +1,25 @@ +{ + "object": { + "pins": [ + { + "package": "swift-nio", + "repositoryURL": "https://github.com/apple/swift-nio.git", + "state": { + "branch": null, + "revision": "334815f6580b5256409d48431751938c4e966e72", + "version": "2.4.0" + } + }, + { + "package": "WebError", + "repositoryURL": "https://github.com/Einstore/WebErrorKit.git", + "state": { + "branch": null, + "revision": "183170b95c46ca5a900d0ea870980c9c280a573a", + "version": "0.0.1" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..19b5a9d --- /dev/null +++ b/Package.swift @@ -0,0 +1,25 @@ +// swift-tools-version:5.1 +import PackageDescription + +let package = Package( + name: "NIOErrorKit", + products: [ + .library(name: "NIOErrorKit", targets: ["NIOErrorKit"]) + ], + dependencies: [ + .package(url: "https://github.com/apple/swift-nio.git", from: "2.3.0"), + .package(url: "https://github.com/Einstore/WebErrorKit.git", from: "0.0.1") + ], + targets: [ + .target( + name: "NIOErrorKit", + dependencies: [ + "WebErrorKit", + "NIO", + "NIOHTTP1" + ] + ) + ] +) + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..362f3f3 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# NIOErrorKit + + + +### Install using SPM + +```swift +.package(url: "https://github.com/Einstore/NIOErrorKit.git", from: "0.0.1") +``` + +### Author + +Ondrej Rafaj @rafiki270 + +### License + +MIT; Copyright 2019 - Einstore diff --git a/Sources/NIOErrorKit/Exports.swift b/Sources/NIOErrorKit/Exports.swift new file mode 100644 index 0000000..0c17389 --- /dev/null +++ b/Sources/NIOErrorKit/Exports.swift @@ -0,0 +1,3 @@ +@_exported import WebErrorKit +@_exported import protocol NIO.EventLoop +@_exported import class NIO.EventLoopFuture diff --git a/Sources/NIOErrorKit/WebError+NIO.swift b/Sources/NIOErrorKit/WebError+NIO.swift new file mode 100644 index 0000000..a275f9f --- /dev/null +++ b/Sources/NIOErrorKit/WebError+NIO.swift @@ -0,0 +1,16 @@ +import NIO +import NIOHTTP1 +import WebErrorKit + +extension WebError { + + public func fail(on e: EventLoop) -> EventLoopFuture { + return e.makeFailedFuture(self) + } + + public var status: HTTPResponseStatus { + return HTTPResponseStatus(statusCode: statusCode, reasonPhrase: reason ?? "") + } + +} +