| | |
| | | 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) { |