{"record":{"id":"2b04c257dd35f89c","repo":"justauth/JustAuth","slug":"object-getstring-error-2b04c2","errorCode":null,"errorMessage":"object.getString(\"error\")","messagePattern":"object\\.getString\\(\"error\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java","lineNumber":180,"sourceCode":"     * 获取用户的实际性别。华为系统中，用户的性别：1表示女，0表示男\n     *\n     * @param object obj\n     * @return AuthUserGender\n     */\n    private AuthUserGender getRealGender(JSONObject object) {\n        int genderCodeInt = object.getIntValue(\"gender\");\n        String genderCode = genderCodeInt == 1 ? \"0\" : (genderCodeInt == 0) ? \"1\" : genderCodeInt + \"\";\n        return AuthUserGender.getRealGender(genderCode);\n    }\n\n    /**\n     * 校验响应结果\n     *\n     * @param object 接口返回的结果\n     */\n    private void checkResponse(JSONObject object) {\n        if (object.containsKey(\"NSP_STATUS\")) {\n            throw new AuthException(object.getString(\"error\"));\n        }\n        if (object.containsKey(\"error\")) {\n            throw new AuthException(object.getString(\"sub_error\") + \":\" + object.getString(\"error_description\"));\n        }\n    }\n}\n","sourceCodeStart":162,"sourceCodeEnd":187,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java#L162-L187","documentation":"First branch of AuthHuaweiRequest.checkResponse(): Huawei's account service signals token-endpoint failures with a top-level 'NSP_STATUS' code, and this code throws AuthException reading the sibling 'error' key. Caveat: NSP_STATUS responses often do not include an 'error' field, so the thrown message can be null - log the raw response when the message is empty.","triggerScenarios":"getAccessToken()/refresh() with a wrong app secret, an invalid or expired authorization code, or an unregistered callback domain - Huawei answers with NSP_STATUS (e.g. NSP_STATUS 500 in the body) indicating the token request failed.","commonSituations":"App Gallery Connect credentials rotated; the callback URL domain not configured in the Huawei app's redirect settings; signature digest (SHA-256 fingerprint) of the calling backend not registered, so Huawei rejects the exchange.","solutions":["Re-copy client_id/client_secret from App Gallery Connect and confirm the app's OAuth 2.0 redirect settings include your callback.","When the exception message is null, enable response logging to capture the NSP_STATUS value and map it against Huawei's error table.","Ensure the authorization code from the callback is exchanged once and immediately.","Verify your app's signing fingerprint is registered if the Huawei console requires it for server-side token exchange."],"exampleFix":"// before - 'error' key may be absent when NSP_STATUS is present, yielding null\nif (object.containsKey(\"NSP_STATUS\")) {\n    throw new AuthException(object.getString(\"error\"));\n}\n\n// after - include the NSP status so the message is never empty\nif (object.containsKey(\"NSP_STATUS\")) {\n    String msg = object.getString(\"error\");\n    throw new AuthException(msg != null ? msg : \"NSP_STATUS \" + object.getString(\"NSP_STATUS\"));\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return huaweiRequest.getAccessToken(callback);\n} catch (AuthException e) {\n    // message may be null for NSP_STATUS failures - degrade gracefully\n    String safe = e.getErrorMsg() != null ? e.getErrorMsg() : \"Huawei token request failed (NSP_STATUS)\";\n    log.warn(\"Huawei NSP error: {}\", safe);\n    return AuthResponse.builder().code(500).msg(safe).build();\n}","preventionTips":["Always null-check AuthException.getErrorMsg() for Huawei - NSP_STATUS bodies often lack an 'error' field.","Log raw HTTP bodies in staging to correlate NSP_STATUS values with Huawei's error documentation.","Keep App Gallery Connect credentials, redirect settings, and signing fingerprints registered and current."],"tags":["oauth","huawei","justauth","api-error","null-message"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}