google.golang.org/grpc@v1.72.2/internal/transport/grpchttp2/errors.go (about) 1 /* 2 * 3 * Copyright 2024 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package grpchttp2 20 21 import "fmt" 22 23 // ErrCode represents an HTTP/2 Error Code. Error codes are 32-bit fields 24 // that are used in [RST_STREAM] and [GOAWAY] frames to convey the reasons for 25 // the stream or connection error. See [HTTP/2 Error Code] for definitions of 26 // each of the following error codes. 27 // 28 // [HTTP/2 Error Code]: https://httpwg.org/specs/rfc7540.html#ErrorCodes 29 // [RST_STREAM]: https://httpwg.org/specs/rfc7540.html#RST_STREAM 30 // [GOAWAY]: https://httpwg.org/specs/rfc7540.html#GOAWAY 31 type ErrCode uint32 32 33 // Error Codes defined by the HTTP/2 Spec. 34 const ( 35 ErrCodeNoError ErrCode = 0x0 36 ErrCodeProtocol ErrCode = 0x1 37 ErrCodeInternal ErrCode = 0x2 38 ErrCodeFlowControl ErrCode = 0x3 39 ErrCodeSettingsTimeout ErrCode = 0x4 40 ErrCodeStreamClosed ErrCode = 0x5 41 ErrCodeFrameSize ErrCode = 0x6 42 ErrCodeRefusedStream ErrCode = 0x7 43 ErrCodeCancel ErrCode = 0x8 44 ErrCodeCompression ErrCode = 0x9 45 ErrCodeConnect ErrCode = 0xa 46 ErrCodeEnhanceYourCalm ErrCode = 0xb 47 ErrCodeInadequateSecurity ErrCode = 0xc 48 ErrCodeHTTP11Required ErrCode = 0xd 49 ) 50 51 var errorCodeNames = map[ErrCode]string{ 52 ErrCodeNoError: "NO_ERROR", 53 ErrCodeProtocol: "PROTOCOL_ERROR", 54 ErrCodeInternal: "INTERNAL_ERROR", 55 ErrCodeFlowControl: "FLOW_CONTROL_ERROR", 56 ErrCodeSettingsTimeout: "SETTINGS_TIMEOUT", 57 ErrCodeStreamClosed: "STREAM_CLOSED", 58 ErrCodeFrameSize: "FRAME_SIZE_ERROR", 59 ErrCodeRefusedStream: "REFUSED_STREAM", 60 ErrCodeCancel: "CANCEL", 61 ErrCodeCompression: "COMPRESSION_ERROR", 62 ErrCodeConnect: "CONNECT_ERROR", 63 ErrCodeEnhanceYourCalm: "ENHANCE_YOUR_CALM", 64 ErrCodeInadequateSecurity: "INADEQUATE_SECURITY", 65 ErrCodeHTTP11Required: "HTTP_1_1_REQUIRED", 66 } 67 68 func (err ErrCode) String() string { 69 if v, ok := errorCodeNames[err]; ok { 70 return v 71 } 72 return fmt.Sprintf("unknown error code %#x", uint32(err)) 73 }