| | |
| | | |
| | | IntegrationRecord record = new IntegrationRecord( |
| | | String.valueOf(snowflakeIdWorker.nextId()).substring(3), // 编号 |
| | | context.getNamespaceType().name(), // 名称空间 |
| | | context.getNamespaceType().desc, // 名称空间 |
| | | payload.getUri(), // 接口地址 |
| | | request.getHeader(HEADER_APP_KEY), // 平台密钥 |
| | | context.getNamespaceType().caller, // 调用方标识 |
| | |
| | | return record; |
| | | } |
| | | |
| | | private void applyResult(IntegrationRecord record, Object body, Exception failure) { |
| | | private void applyResult(IntegrationRecord record, Object responseBody, Exception failure) { |
| | | if (failure != null) { |
| | | record.setResult(0); |
| | | record.setErr(failure.getMessage()); |
| | | record.setErr("Request failed: " + failure.getMessage()); |
| | | return; |
| | | } |
| | | if (!(body instanceof R)) { |
| | | record.setResult(null); |
| | | record.setErr(null); |
| | | if (!(responseBody instanceof R)) { |
| | | record.setErr("Invalid response body structure. Expected: { code, msg, data }."); |
| | | return; |
| | | } |
| | | R response = (R) body; |
| | | Integer code = parseInteger(response.get("code")); |
| | | R r = (R) responseBody; |
| | | Integer code = parseInteger(r.get("code")); |
| | | if (code == null) { |
| | | record.setResult(null); |
| | | record.setErr(null); |
| | | record.setErr("Missing or invalid response field: code."); |
| | | return; |
| | | } |
| | | boolean success = code == 200; |
| | | record.setResult(success ? 1 : 0); |
| | | record.setErr(success ? null : String.valueOf(response.get("msg"))); |
| | | if (code == 200) { |
| | | record.setResult(1); |
| | | } |
| | | } |
| | | |
| | | private Integer parseInteger(Object codeObj) { |