MCPcopy Create free account
hub / github.com/DoNewsCode/core / Example

Function Example

unierr/example_test.go:11–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func Example() {
12 fmt.Printf("Default status conversion:\n")
13 for i := 1; i < 17; i++ {
14 err := unierr.Wrap(errors.New(""), codes.Code(i))
15 fmt.Printf("GRPC %d <=> HTTP: %d\n", err.GRPCStatus().Code(), err.StatusCode())
16 }
17 // Output:
18 // Default status conversion:
19 // GRPC 1 <=> HTTP: 499
20 // GRPC 2 <=> HTTP: 500
21 // GRPC 3 <=> HTTP: 400
22 // GRPC 4 <=> HTTP: 504
23 // GRPC 5 <=> HTTP: 404
24 // GRPC 6 <=> HTTP: 409
25 // GRPC 7 <=> HTTP: 403
26 // GRPC 8 <=> HTTP: 429
27 // GRPC 9 <=> HTTP: 400
28 // GRPC 10 <=> HTTP: 409
29 // GRPC 11 <=> HTTP: 400
30 // GRPC 12 <=> HTTP: 501
31 // GRPC 13 <=> HTTP: 500
32 // GRPC 14 <=> HTTP: 500
33 // GRPC 15 <=> HTTP: 500
34 // GRPC 16 <=> HTTP: 401
35}
36
37func ExampleError_StatusCode() {
38 err := errors.New("my stuff is missing")

Callers

nothing calls this directly

Calls 4

WrapFunction · 0.92
GRPCStatusMethod · 0.80
StatusCodeMethod · 0.65
PrintfMethod · 0.45

Tested by

no test coverage detected