|
12 | 12 | const ConfigManager = require('./configmanager')
|
13 | 13 | const { LoggerUtil } = require('helios-core')
|
14 | 14 | const { RestResponseStatus } = require('helios-core/common')
|
15 |
| -const { MojangRestAPI, mojangErrorDisplayable, MojangErrorCode } = require('helios-core/mojang') |
16 |
| -const { MicrosoftAuth, microsoftErrorDisplayable, MicrosoftErrorCode } = require('helios-core/microsoft') |
| 15 | +const { MojangRestAPI, MojangErrorCode } = require('helios-core/mojang') |
| 16 | +const { MicrosoftAuth, MicrosoftErrorCode } = require('helios-core/microsoft') |
17 | 17 | const { AZURE_CLIENT_ID } = require('./ipcconstants')
|
| 18 | +const Lang = require('./langloader') |
18 | 19 |
|
19 | 20 | const log = LoggerUtil.getLogger('AuthManager')
|
20 | 21 |
|
| 22 | +// Error messages |
| 23 | + |
| 24 | +function microsoftErrorDisplayable(errorCode) { |
| 25 | + switch (errorCode) { |
| 26 | + case MicrosoftErrorCode.NO_PROFILE: |
| 27 | + return { |
| 28 | + title: Lang.queryJS('auth.microsoft.error.noProfileTitle'), |
| 29 | + desc: Lang.queryJS('auth.microsoft.error.noProfileDesc') |
| 30 | + } |
| 31 | + case MicrosoftErrorCode.NO_XBOX_ACCOUNT: |
| 32 | + return { |
| 33 | + title: Lang.queryJS('auth.microsoft.error.noXboxAccountTitle'), |
| 34 | + desc: Lang.queryJS('auth.microsoft.error.noXboxAccountDesc') |
| 35 | + } |
| 36 | + case MicrosoftErrorCode.XBL_BANNED: |
| 37 | + return { |
| 38 | + title: Lang.queryJS('auth.microsoft.error.xblBannedTitle'), |
| 39 | + desc: Lang.queryJS('auth.microsoft.error.xblBannedDesc') |
| 40 | + } |
| 41 | + case MicrosoftErrorCode.UNDER_18: |
| 42 | + return { |
| 43 | + title: Lang.queryJS('auth.microsoft.error.under18Title'), |
| 44 | + desc: Lang.queryJS('auth.microsoft.error.under18Desc') |
| 45 | + } |
| 46 | + case MicrosoftErrorCode.UNKNOWN: |
| 47 | + return { |
| 48 | + title: Lang.queryJS('auth.microsoft.error.unknownTitle'), |
| 49 | + desc: Lang.queryJS('auth.microsoft.error.unknownDesc') |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +function mojangErrorDisplayable(errorCode) { |
| 55 | + switch(errorCode) { |
| 56 | + case MojangErrorCode.ERROR_METHOD_NOT_ALLOWED: |
| 57 | + return { |
| 58 | + title: Lang.queryJS('auth.mojang.error.methodNotAllowedTitle'), |
| 59 | + desc: Lang.queryJS('auth.mojang.error.methodNotAllowedDesc') |
| 60 | + } |
| 61 | + case MojangErrorCode.ERROR_NOT_FOUND: |
| 62 | + return { |
| 63 | + title: Lang.queryJS('auth.mojang.error.notFoundTitle'), |
| 64 | + desc: Lang.queryJS('auth.mojang.error.notFoundDesc') |
| 65 | + } |
| 66 | + case MojangErrorCode.ERROR_USER_MIGRATED: |
| 67 | + return { |
| 68 | + title: Lang.queryJS('auth.mojang.error.accountMigratedTitle'), |
| 69 | + desc: Lang.queryJS('auth.mojang.error.accountMigratedDesc') |
| 70 | + } |
| 71 | + case MojangErrorCode.ERROR_INVALID_CREDENTIALS: |
| 72 | + return { |
| 73 | + title: Lang.queryJS('auth.mojang.error.invalidCredentialsTitle'), |
| 74 | + desc: Lang.queryJS('auth.mojang.error.invalidCredentialsDesc') |
| 75 | + } |
| 76 | + case MojangErrorCode.ERROR_RATELIMIT: |
| 77 | + return { |
| 78 | + title: Lang.queryJS('auth.mojang.error.tooManyAttemptsTitle'), |
| 79 | + desc: Lang.queryJS('auth.mojang.error.tooManyAttemptsDesc') |
| 80 | + } |
| 81 | + case MojangErrorCode.ERROR_INVALID_TOKEN: |
| 82 | + return { |
| 83 | + title: Lang.queryJS('auth.mojang.error.invalidTokenTitle'), |
| 84 | + desc: Lang.queryJS('auth.mojang.error.invalidTokenDesc') |
| 85 | + } |
| 86 | + case MojangErrorCode.ERROR_ACCESS_TOKEN_HAS_PROFILE: |
| 87 | + return { |
| 88 | + title: Lang.queryJS('auth.mojang.error.tokenHasProfileTitle'), |
| 89 | + desc: Lang.queryJS('auth.mojang.error.tokenHasProfileDesc') |
| 90 | + } |
| 91 | + case MojangErrorCode.ERROR_CREDENTIALS_MISSING: |
| 92 | + return { |
| 93 | + title: Lang.queryJS('auth.mojang.error.credentialsMissingTitle'), |
| 94 | + desc: Lang.queryJS('auth.mojang.error.credentialsMissingDesc') |
| 95 | + } |
| 96 | + case MojangErrorCode.ERROR_INVALID_SALT_VERSION: |
| 97 | + return { |
| 98 | + title: Lang.queryJS('auth.mojang.error.invalidSaltVersionTitle'), |
| 99 | + desc: Lang.queryJS('auth.mojang.error.invalidSaltVersionDesc') |
| 100 | + } |
| 101 | + case MojangErrorCode.ERROR_UNSUPPORTED_MEDIA_TYPE: |
| 102 | + return { |
| 103 | + title: Lang.queryJS('auth.mojang.error.unsupportedMediaTypeTitle'), |
| 104 | + desc: Lang.queryJS('auth.mojang.error.unsupportedMediaTypeDesc') |
| 105 | + } |
| 106 | + case MojangErrorCode.ERROR_GONE: |
| 107 | + return { |
| 108 | + title: Lang.queryJS('auth.mojang.error.accountGoneTitle'), |
| 109 | + desc: Lang.queryJS('auth.mojang.error.accountGoneDesc') |
| 110 | + } |
| 111 | + case MojangErrorCode.ERROR_UNREACHABLE: |
| 112 | + return { |
| 113 | + title: Lang.queryJS('auth.mojang.error.unreachableTitle'), |
| 114 | + desc: Lang.queryJS('auth.mojang.error.unreachableDesc') |
| 115 | + } |
| 116 | + case MojangErrorCode.ERROR_NOT_PAID: |
| 117 | + return { |
| 118 | + title: Lang.queryJS('auth.mojang.error.gameNotPurchasedTitle'), |
| 119 | + desc: Lang.queryJS('auth.mojang.error.gameNotPurchasedDesc') |
| 120 | + } |
| 121 | + case MojangErrorCode.UNKNOWN: |
| 122 | + return { |
| 123 | + title: Lang.queryJS('auth.mojang.error.unknownErrorTitle'), |
| 124 | + desc: Lang.queryJS('auth.mojang.error.unknownErrorDesc') |
| 125 | + } |
| 126 | + default: |
| 127 | + throw new Error(`Unknown error code: ${errorCode}`) |
| 128 | + } |
| 129 | +} |
| 130 | + |
21 | 131 | // Functions
|
22 | 132 |
|
23 | 133 | /**
|
|
0 commit comments