|
| 1 | +// Copyright 2017-2020 @polkadot/rpc-provider authors & contributors |
| 2 | +// This software may be modified and distributed under the terms |
| 3 | +// of the Apache-2.0 license. See the LICENSE file for details. |
| 4 | + |
| 5 | +// from https://stackoverflow.com/questions/19304157/getting-the-reason-why-websockets-closed-with-close-code-1006 |
| 6 | + |
| 7 | +const specificStatusCodeMappings: Record<number, string> = { |
| 8 | + 1000: 'Normal Closure', |
| 9 | + 1001: 'Going Away', |
| 10 | + 1002: 'Protocol Error', |
| 11 | + 1003: 'Unsupported Data', |
| 12 | + 1004: '(For future)', |
| 13 | + 1005: 'No Status Received', |
| 14 | + 1006: 'Abnormal Closure', |
| 15 | + 1007: 'Invalid frame payload data', |
| 16 | + 1008: 'Policy Violation', |
| 17 | + 1009: 'Message too big', |
| 18 | + 1010: 'Missing Extension', |
| 19 | + 1011: 'Internal Error', |
| 20 | + 1012: 'Service Restart', |
| 21 | + 1013: 'Try Again Later', |
| 22 | + 1014: 'Bad Gateway', |
| 23 | + 1015: 'TLS Handshake' |
| 24 | +}; |
| 25 | + |
| 26 | +export function getWSErrorString (code: number): string { |
| 27 | + if (code >= 0 && code <= 999) { |
| 28 | + return '(Unused)'; |
| 29 | + } else if (code >= 1016) { |
| 30 | + if (code <= 1999) { |
| 31 | + return '(For WebSocket standard)'; |
| 32 | + } else if (code <= 2999) { |
| 33 | + return '(For WebSocket extensions)'; |
| 34 | + } else if (code <= 3999) { |
| 35 | + return '(For libraries and frameworks)'; |
| 36 | + } else if (code <= 4999) { |
| 37 | + return '(For applications)'; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + return specificStatusCodeMappings[code] || '(Unknown)'; |
| 42 | +} |
0 commit comments