|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | """
|
3 |
| -hyper/http20/error_code_registry |
4 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3 | +hyper/http20/errorserrors |
| 4 | +~~~~~~~~~~~~~~~~~~~ |
5 | 5 |
|
6 | 6 | Global error code registry containing the established HTTP/2 error codes.
|
7 | 7 | The registry is based on a 32-bit space so we use the error code to index into
|
|
12 | 12 | """
|
13 | 13 |
|
14 | 14 | NO_ERROR = {'Name': 'NO_ERROR',
|
| 15 | + 'Code': '0x0', |
15 | 16 | 'Description': 'Graceful shutdown'}
|
16 | 17 | PROTOCOL_ERROR = {'Name': 'PROTOCOL_ERROR',
|
| 18 | + 'Code': '0x1', |
17 | 19 | 'Description': 'Protocol error detected'}
|
18 | 20 | INTERNAL_ERROR = {'Name': 'INTERNAL_ERROR',
|
| 21 | + 'Code': '0x2', |
19 | 22 | 'Description': 'Implementation fault'}
|
20 | 23 | FLOW_CONTROL_ERROR = {'Name': 'FLOW_CONTROL_ERROR',
|
| 24 | + 'Code': '0x3', |
21 | 25 | 'Description': 'Flow control limits exceeded'}
|
22 | 26 | SETTINGS_TIMEOUT = {'Name': 'SETTINGS_TIMEOUT',
|
| 27 | + 'Code': '0x4', |
23 | 28 | 'Description': 'Settings not acknowledged'}
|
24 | 29 | STREAM_CLOSED = {'Name': 'STREAM_CLOSED',
|
| 30 | + 'Code': '0x5', |
25 | 31 | 'Description': 'Frame received for closed stream'}
|
26 | 32 | FRAME_SIZE_ERROR = {'Name': 'FRAME_SIZE_ERROR',
|
| 33 | + 'Code': '0x6', |
27 | 34 | 'Description': 'Frame size incorrect'}
|
28 | 35 | REFUSED_STREAM = {'Name': 'REFUSED_STREAM ',
|
| 36 | + 'Code': '0x7', |
29 | 37 | 'Description': 'Stream not processed'}
|
30 | 38 | CANCEL = {'Name': 'CANCEL',
|
| 39 | + 'Code': '0x8', |
31 | 40 | 'Description': 'Stream cancelled'}
|
32 | 41 | COMPRESSION_ERROR = {'Name': 'COMPRESSION_ERROR',
|
| 42 | + 'Code': '0x9', |
33 | 43 | 'Description': 'Compression state not updated'}
|
34 | 44 | CONNECT_ERROR = {'Name': 'CONNECT_ERROR',
|
| 45 | + 'Code': '0xa', |
35 | 46 | 'Description':
|
36 | 47 | 'TCP connection error for CONNECT method'}
|
37 | 48 | ENHANCE_YOUR_CALM = {'Name': 'ENHANCE_YOUR_CALM',
|
| 49 | + 'Code': '0xb', |
38 | 50 | 'Description': 'Processing capacity exceeded'}
|
39 | 51 | INADEQUATE_SECURITY = {'Name': 'INADEQUATE_SECURITY',
|
| 52 | + 'Code': '0xc', |
40 | 53 | 'Description':
|
41 | 54 | 'Negotiated TLS parameters not acceptable'}
|
42 | 55 | HTTP_1_1_REQUIRED = {'Name': 'HTTP_1_1_REQUIRED',
|
| 56 | + 'Code': '0xd', |
43 | 57 | 'Description': 'Use HTTP/1.1 for the request'}
|
44 | 58 |
|
45 |
| -H2_ERROR_CODE_REGISTRY = [NO_ERROR, PROTOCOL_ERROR, INTERNAL_ERROR, |
46 |
| - FLOW_CONTROL_ERROR, SETTINGS_TIMEOUT, STREAM_CLOSED, |
47 |
| - FRAME_SIZE_ERROR, REFUSED_STREAM, CANCEL, |
48 |
| - COMPRESSION_ERROR, CONNECT_ERROR, ENHANCE_YOUR_CALM, |
49 |
| - INADEQUATE_SECURITY, HTTP_1_1_REQUIRED] |
| 59 | +H2_ERRORS = [NO_ERROR, PROTOCOL_ERROR, INTERNAL_ERROR, FLOW_CONTROL_ERROR, |
| 60 | + SETTINGS_TIMEOUT, STREAM_CLOSED, FRAME_SIZE_ERROR, REFUSED_STREAM, |
| 61 | + CANCEL, COMPRESSION_ERROR, CONNECT_ERROR, ENHANCE_YOUR_CALM, |
| 62 | + INADEQUATE_SECURITY, HTTP_1_1_REQUIRED] |
| 63 | + |
| 64 | +def get_data(error_code): |
| 65 | + """ |
| 66 | + Lookup the error code description, if not available throw a value error |
| 67 | + """ |
| 68 | + if error_code < 0 or error_code >= len(H2_ERRORS): |
| 69 | + raise ValueError("Error code is invalid") |
| 70 | + |
| 71 | + name = H2_ERRORS[error_code]['Name'] |
| 72 | + number = H2_ERRORS[error_code]['Code'] |
| 73 | + description = H2_ERRORS[error_code]['Description'] |
| 74 | + |
| 75 | + return name, number, description |
0 commit comments