errors.py 3.2 KB

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