{"record":{"id":"6b76d556b7e71801","repo":"apache/shenyu","slug":"dingtalk-notify-error-e-getmessage","errorCode":null,"errorMessage":"[DingTalk Notify Error] \" + e.getMessage()","messagePattern":"\\[DingTalk Notify Error\\] \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"AlertNoticeException","httpStatus":null,"severity":"error","filePath":"shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/DingTalkRobotAlertNotifyStrategy.java","lineNumber":71,"sourceCode":"            headers.setContentType(MediaType.APPLICATION_JSON);\n            HttpEntity<DingTalkWebHookDto> httpEntity = new HttpEntity<>(dingTalkWebHookDto, headers);\n            String webHookUrl = DING_TALK_WEB_HOOK_URL + receiver.getAccessToken();\n            ResponseEntity<CommonRobotNotifyResp> responseEntity = getRestTemplate().postForEntity(webHookUrl,\n                    httpEntity, CommonRobotNotifyResp.class);\n            if (responseEntity.getStatusCode() == HttpStatus.OK) {\n                Objects.requireNonNull(responseEntity.getBody());\n                if (responseEntity.getBody().getErrCode() == 0) {\n                    log.debug(\"Send dingTalk webHook: {} Success\", webHookUrl);\n                } else {\n                    log.warn(\"Send dingTalk webHook: {} Failed: {}\", webHookUrl, responseEntity.getBody().getErrMsg());\n                    throw new AlertNoticeException(responseEntity.getBody().getErrMsg());\n                }\n            } else {\n                log.warn(\"Send dingTalk webHook: {} Failed: {}\", webHookUrl, responseEntity.getBody());\n                throw new AlertNoticeException(\"Http StatusCode \" + responseEntity.getStatusCode());\n            }\n        } catch (Exception e) {\n            throw new AlertNoticeException(\"[DingTalk Notify Error] \" + e.getMessage());\n        }\n    }\n    \n    @Override\n    public byte type() {\n        return 5;\n    }\n    \n    @Override\n    protected String templateName() {\n        return \"alertNotifyDingTalkRobot\";\n    }\n    \n    /**\n     * DingDing body.\n     */\n    private static class DingTalkWebHookDto {\n        private static final String MARKDOWN = \"markdown\";","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/DingTalkRobotAlertNotifyStrategy.java#L53-L89","documentation":"Catch-all in DingTalkRobotAlertNotifyStrategy.send: any Exception during building/sending the request (serialization, IO, timeout, NPE on body) is rethrown as AlertNoticeException(\"[DingTalk Notify Error] \" + e.getMessage()). It indicates the notification pipeline failed before/at the HTTP call, and it also swallows the earlier AlertNoticeExceptions by re-wrapping them.","triggerScenarios":"Any exception inside send(): RestTemplate IO error, connect/read timeout, JSON serialization failure of the alert payload, or Objects.requireNonNull(responseEntity.getBody()) NPE on an empty body.","commonSituations":"Network outages or DNS failures reaching oapi.dingtalk.com; request timeouts under load; body unexpectedly empty so requireNonNull throws; alert content with characters that break serialization.","solutions":["Check application logs for the root stack trace (the cause is preserved in the wrapping catch)","Test webhook connectivity (timeout/DNS) from the host running the alert sender","Increase RestTemplate connect/read timeouts if failures occur under load","Handle empty/invalid response bodies explicitly instead of relying on requireNonNull"],"exampleFix":"// before\ncatch (Exception e) {\n    throw new AlertNoticeException(\"[DingTalk Notify Error] \" + e.getMessage());\n}\n// after\ncatch (AlertNoticeException e) {\n    throw e;\n} catch (Exception e) {\n    throw new AlertNoticeException(\"[DingTalk Notify Error] \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"// ensure webhook url set and network reachable before sending\nObjects.requireNonNull(webHookUrl, \"dingtalk webhook url must be set\");","typeGuard":null,"tryCatchPattern":"try {\n    strategy.send(config, alert);\n} catch (AlertNoticeException e) {\n    log.error(\"DingTalk notify failed: {}\", e.getMessage(), e);\n    // use alternate notification strategy (email/sms)\n}","preventionTips":["Set generous connect/read timeouts on the RestTemplate used for webhooks","Test alert delivery after network changes or deployments","Log the full cause of wrapped exceptions to speed diagnosis"],"tags":["dingtalk","webhook","alert","network"],"backgroundTag":"network-request-failed","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}