-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrors.cs
89 lines (76 loc) · 2.27 KB
/
Errors.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Protocol = Hrpc.V1;
namespace Hrpc;
public class HrpcError : Exception
{
public readonly string Identifier;
public readonly string HumanMessage;
public readonly byte[] Details;
public HrpcError(Protocol.Error error)
{
Identifier = error.Identifier;
HumanMessage = error.HumanMessage;
Details = error.Details.ToByteArray();
}
}
public class UnknownHrpcError : HrpcError
{
public UnknownHrpcError(Protocol.Error error) : base(error) { }
}
public class InternalServerError : HrpcError
{
public InternalServerError(Protocol.Error error) : base(error) { }
}
public class RateLimited : HrpcError
{
public readonly uint RetryAfter;
public RateLimited(Protocol.Error error) : base(error)
{
var details = Protocol.RetryInfo.Parser.ParseFrom(error.Details);
RetryAfter = details.RetryAfter;
}
}
public class NotFound : HrpcError
{
public NotFound(Protocol.Error error) : base(error) { }
}
public class NotImplemented : HrpcError
{
public NotImplemented(Protocol.Error error) : base(error) { }
}
public class Unavailable : HrpcError
{
public Unavailable(Protocol.Error error) : base(error) { }
}
public class BadUnaryRequest : HrpcError
{
public BadUnaryRequest(Protocol.Error error) : base(error) { }
}
public class BadStreamingRequest : HrpcError
{
public BadStreamingRequest(Protocol.Error error) : base(error) { }
}
internal static class ErrorsExt
{
internal static HrpcError ParseError(Protocol.Error error)
{
switch (error.Identifier)
{
case "hrpc.internal-server-error":
return new InternalServerError(error);
case "hrpc.resource-exhausted":
return new RateLimited(error);
case "hrpc.not-found":
return new NotFound(error);
case "hrpc.not-implemented":
return new NotImplemented(error);
case "hrpc.unavailable":
return new Unavailable(error);
case "hrpc.http.bad-unary-request":
return new BadUnaryRequest(error);
case "hrpc.http.bad-streaming-request":
return new BadStreamingRequest(error);
default:
return new UnknownHrpcError(error);
}
}
}