Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cause to GRPCStatus.processingError for uncaught errors #1356

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Sources/GRPC/GRPCStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ public struct GRPCStatus: Error {
/// status code. Use `GRPCStatus.isOk` or check the code directly.
public static let ok = GRPCStatus(code: .ok, message: nil)
/// "Internal server error" status.
public static let processingError = GRPCStatus(
code: .internalError,
message: "unknown error processing request"
)
public static let processingError = Self.processingError(cause: nil)

public static func processingError(cause: Error?) -> GRPCStatus {
return GRPCStatus(
code: .internalError,
message: "unknown error processing request",
cause: cause
)
}
}

extension GRPCStatus: Equatable {
Expand Down
4 changes: 2 additions & 2 deletions Sources/GRPC/ServerErrorProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal enum ServerErrorProcessor {
trailers = [:]
} else {
// Eh... well, we don't what status to use. Use a generic one.
status = .processingError
status = .processingError(cause: error)
trailers = [:]
}

Expand Down Expand Up @@ -84,7 +84,7 @@ internal enum ServerErrorProcessor {
mergedTrailers = trailers
} else {
// Eh... well, we don't what status to use. Use a generic one.
status = .processingError
status = .processingError(cause: error)
mergedTrailers = trailers
}

Expand Down