Skip to content

Commit

Permalink
hardcode error response
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jan 27, 2016
1 parent 7086bba commit 14288ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Sources/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,9 @@ public class Response {
}

public convenience init(error: String) {
let object: [String: Any] = [
"error": true,
"message": error
]
try! self.init(status: .Error, json: object)
let text = "{\n\t\"error\": true,\n\t\"message\":\"\(error)\"}"
let data = [UInt8](text.utf8)
self.init(status: .Error, data: data, contentType: .Json)
}

public convenience init(status: Status, html: String) {
Expand Down
20 changes: 20 additions & 0 deletions Sources/ResponseConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ extension String: ResponseConvertible {
}
}

extension Dictionary: ResponseConvertible {
public func response() -> Response {
do {
return try Response(status: .OK, json: self)
} catch {
return Response(error: "JSON serialization error: \(error)")
}
}
}

extension Array: ResponseConvertible {
public func response() -> Response {
do {
return try Response(status: .OK, json: self)
} catch {
return Response(error: "JSON serialization error: \(error)")
}
}
}

extension NSDictionary: ResponseConvertible {
public func response() -> Response {
do {
Expand Down

0 comments on commit 14288ad

Please sign in to comment.