Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from nodes-vapor/abort-sugar
Browse files Browse the repository at this point in the history
Added report and doNotReport extensions to Abort. Register configurab…
  • Loading branch information
BrettRToomey authored Jun 28, 2017
2 parents 65c5e0a + 7614e56 commit 69b6d77
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
30 changes: 30 additions & 0 deletions Sources/Bugsnag/Abort+Report.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Vapor

extension Abort {
public func report() -> Abort {
return addReportMetadata(true)
}

public func doNotReport() -> Abort {
return addReportMetadata(false)
}

func addReportMetadata(_ shouldReport: Bool) -> Abort {
var metadata = self.metadata ?? Node.object([:])
try? metadata.set("report", shouldReport)

let result = Abort.init(
status,
metadata: metadata,
reason: reason,
identifier: identifier,
possibleCauses: possibleCauses,
suggestedFixes: suggestedFixes,
documentationLinks: documentationLinks,
stackOverflowQuestions: stackOverflowQuestions,
gitHubIssues: gitHubIssues
)

return result
}
}
1 change: 1 addition & 0 deletions Sources/Bugsnag/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class Provider: Vapor.Provider {
}

self.config = try BugsnagConfig(config)
try config.addConfigurable(middleware: Middleware(config: config), name: "bugsnag")
}

// is automatically called directly after boot()
Expand Down
18 changes: 17 additions & 1 deletion Tests/BugsnagTests/PayloadTransformerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class PayloadTransformerTests: XCTestCase {
("testThatQueryParametersGetsFiltered", testThatQueryParametersGetsFiltered),
("testThatFormParametersGetsFiltered", testThatFormParametersGetsFiltered),
("testThatJsonParametersGetsFiltered", testThatJsonParametersGetsFiltered),
("testThatStackTraceSizeIsWorking", testThatStackTraceSizeIsWorking)
("testThatStackTraceSizeIsWorking", testThatStackTraceSizeIsWorking),
("testAbortExtensions", testAbortExtensions)
]

override func setUp() {
Expand Down Expand Up @@ -192,4 +193,19 @@ class PayloadTransformerTests: XCTestCase {
XCTAssertEqual(FrameAddressMock.lastStackSize, 99)

}

func testAbortExtensions() {
let errorReported = Abort.serverError.report()
let errorNotReported = Abort.serverError.doNotReport()

// ensure status code is the same
XCTAssertEqual(errorReported.status, Abort.serverError.status)
XCTAssertEqual(errorNotReported.status, Abort.serverError.status)

XCTAssertNotNil(errorReported.metadata)
XCTAssertNotNil(errorNotReported.metadata)

XCTAssertEqual(errorReported.metadata?["report"]?.bool, true)
XCTAssertEqual(errorNotReported.metadata?["report"]?.bool, false)
}
}
1 change: 0 additions & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ XCTMain([
testCase(MiddlewareTests.allTests),
testCase(PayloadTransformerTests.allTests),
testCase(ReporterTests.allTests),
testCase(ConnectionManagerTests.allTests),
testCase(ConfigurationTests.allTests)
])

0 comments on commit 69b6d77

Please # to comment.