-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from moleike/add-status-codes
Add gRPC status codes
- Loading branch information
Showing
6 changed files
with
147 additions
and
43 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
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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package org.http4s.grpc | ||
|
||
object GrpcExceptions { | ||
final case class StatusRuntimeException(status: Int, message: Option[String]) | ||
final case class StatusRuntimeException(status: GrpcStatus.Code, message: Option[String]) | ||
extends RuntimeException({ | ||
val me = message.fold("")((m: String) => s", Message-${m}") | ||
s"Grpc Failed: Status-$status${me}" | ||
}) | ||
s"Grpc Failed: Status-${status.value}${me}" | ||
}) { | ||
assert(status != GrpcStatus.Ok) | ||
} | ||
} |
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,68 @@ | ||
package org.http4s.grpc | ||
|
||
import GrpcExceptions.StatusRuntimeException | ||
|
||
object GrpcStatus { | ||
|
||
sealed abstract class Code(val value: Int) extends Product with Serializable { | ||
def asStatusRuntimeException(message: Option[String] = None): StatusRuntimeException = | ||
StatusRuntimeException(this, message) | ||
} | ||
|
||
case object Ok extends Code(0) | ||
|
||
case object Cancelled extends Code(1) | ||
|
||
case object Unknown extends Code(2) | ||
|
||
case object InvalidArgument extends Code(3) | ||
|
||
case object DeadlineExceeded extends Code(4) | ||
|
||
case object NotFound extends Code(5) | ||
|
||
case object AlreadyExists extends Code(6) | ||
|
||
case object PermissionDenied extends Code(7) | ||
|
||
case object ResourceExhausted extends Code(8) | ||
|
||
case object FailedPrecondition extends Code(9) | ||
|
||
case object Aborted extends Code(10) | ||
|
||
case object OutOfRange extends Code(11) | ||
|
||
case object Unimplemented extends Code(12) | ||
|
||
case object Internal extends Code(13) | ||
|
||
case object Unavailable extends Code(14) | ||
|
||
case object DataLoss extends Code(15) | ||
|
||
case object Unauthenticated extends Code(16) | ||
|
||
def fromCodeValue(value: Int): Option[Code] = codeValues.find(_.value == value) | ||
|
||
val codeValues: List[Code] = List( | ||
Ok, | ||
Cancelled, | ||
Unknown, | ||
InvalidArgument, | ||
DeadlineExceeded, | ||
NotFound, | ||
AlreadyExists, | ||
PermissionDenied, | ||
ResourceExhausted, | ||
FailedPrecondition, | ||
Aborted, | ||
OutOfRange, | ||
Unimplemented, | ||
Internal, | ||
Unavailable, | ||
DataLoss, | ||
Unauthenticated, | ||
) | ||
|
||
} |
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
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