MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestDefaultHTTPError

Function TestDefaultHTTPError

runtime/errors_test.go:21–135  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestDefaultHTTPError(t *testing.T) {
22 ctx := context.Background()
23
24 statusWithDetails, _ := status.New(codes.FailedPrecondition, "failed precondition").WithDetails(
25 &errdetails.PreconditionFailure{},
26 )
27
28 for i, spec := range []struct {
29 err error
30 status int
31 msg string
32 marshaler runtime.Marshaler
33 contentType string
34 details string
35 fordwardRespRewriter runtime.ForwardResponseRewriter
36 extractMessage func(*testing.T)
37 }{
38 {
39 err: errors.New("example error"),
40 status: http.StatusInternalServerError,
41 marshaler: &runtime.JSONPb{},
42 contentType: "application/json",
43 msg: "example error",
44 },
45 {
46 err: status.Error(codes.NotFound, "no such resource"),
47 status: http.StatusNotFound,
48 marshaler: &runtime.JSONPb{},
49 contentType: "application/json",
50 msg: "no such resource",
51 },
52 {
53 err: statusWithDetails.Err(),
54 status: http.StatusBadRequest,
55 marshaler: &runtime.JSONPb{},
56 contentType: "application/json",
57 msg: "failed precondition",
58 details: "type.googleapis.com/google.rpc.PreconditionFailure",
59 },
60 {
61 err: errors.New("example error"),
62 status: http.StatusInternalServerError,
63 marshaler: &CustomMarshaler{&runtime.JSONPb{}},
64 contentType: "Custom-Content-Type",
65 msg: "example error",
66 },
67 {
68 err: &runtime.HTTPStatusError{
69 HTTPStatus: http.StatusMethodNotAllowed,
70 Err: status.Error(codes.Unimplemented, http.StatusText(http.StatusMethodNotAllowed)),
71 },
72 status: http.StatusMethodNotAllowed,
73 marshaler: &runtime.JSONPb{},
74 contentType: "application/json",
75 msg: "Method Not Allowed",
76 },
77 {
78 err: status.Error(codes.InvalidArgument, "example error"),

Callers

nothing calls this directly

Calls 6

NewServeMuxFunction · 0.92
HTTPErrorFunction · 0.92
HeaderMethod · 0.80
UnmarshalMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected