| 1 | import { PlatformErrorCategory } from '../platforms/platforms.exception' |
| 2 | |
| 3 | export function categoryFromWeChatErrCode(errcode?: number): PlatformErrorCategory { |
| 4 | if (errcode === undefined) { |
| 5 | return PlatformErrorCategory.Unknown |
| 6 | } |
| 7 | if (errcode === -1) { |
| 8 | return PlatformErrorCategory.PlatformUnavailable |
| 9 | } |
| 10 | if (isWeChatAuthErrCode(errcode)) { |
| 11 | return PlatformErrorCategory.Auth |
| 12 | } |
| 13 | if (isWeChatPermissionErrCode(errcode)) { |
| 14 | return PlatformErrorCategory.Permission |
| 15 | } |
| 16 | if (isWeChatRateLimitErrCode(errcode)) { |
| 17 | return PlatformErrorCategory.RateLimit |
| 18 | } |
| 19 | if (isWeChatNotFoundErrCode(errcode)) { |
| 20 | return PlatformErrorCategory.NotFound |
| 21 | } |
| 22 | if (errcode >= 40000 && errcode < 50000) { |
| 23 | return PlatformErrorCategory.Validation |
| 24 | } |
| 25 | return PlatformErrorCategory.Unknown |
| 26 | } |
| 27 | |
| 28 | export function isWeChatErrCodeRetryable(errcode?: number): boolean { |
| 29 | return errcode === -1 || isWeChatRateLimitErrCode(errcode) |
| 30 | } |
| 31 | |
| 32 | function isWeChatAuthErrCode(errcode: number): boolean { |
| 33 | return errcode === 40001 |
| 34 | || errcode === 40013 |
| 35 | || errcode === 40014 |
| 36 | || errcode === 40029 |
| 37 | || errcode === 40030 |
| 38 | || errcode === 42001 |
| 39 | || errcode === 42002 |
| 40 | || errcode === 42007 |
| 41 | || errcode === 61004 |
| 42 | } |
| 43 | |
| 44 | function isWeChatPermissionErrCode(errcode: number): boolean { |
| 45 | return errcode === 40164 |
| 46 | || errcode === 48001 |
| 47 | || errcode === 48002 |
| 48 | || errcode === 48004 |
| 49 | || errcode === 48005 |
| 50 | } |
| 51 | |
| 52 | function isWeChatRateLimitErrCode(errcode?: number): boolean { |
| 53 | return errcode === 45009 |
| 54 | || errcode === 45011 |
| 55 | || errcode === 45047 |
| 56 | || errcode === 45064 |
| 57 | || errcode === 45065 |
| 58 | } |
| 59 | |
| 60 | function isWeChatNotFoundErrCode(errcode: number): boolean { |
| 61 | return errcode === 40003 |
| 62 | || errcode === 40007 |
| 63 | || errcode === 40037 |
| 64 | } |
| 65 |