fix(im): preserve platform event error semantics
这个提交包含在:
父节点
226bfc488d
当前提交
42f57b2bc6
@ -25,7 +25,6 @@ public class PlatformEventController {
|
||||
public ResponseEntity<ApiResponse<Map<String, String>>> token(
|
||||
@RequestParam String appKey,
|
||||
@RequestParam(defaultValue = "platform") String userId) {
|
||||
try {
|
||||
String userSig = accountService.generateUserSigToken(appKey, userId, 24 * 60 * 60, "");
|
||||
ImAccountService.LoginResult result = accountService.loginWithUserSig(appKey, userId, userSig);
|
||||
Map<String, String> data = new LinkedHashMap<>();
|
||||
@ -34,8 +33,5 @@ public class PlatformEventController {
|
||||
data.put("token", result.token());
|
||||
data.put("admin", String.valueOf(result.admin()));
|
||||
return ResponseEntity.ok(ApiResponse.success(data));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(500).body(ApiResponse.error(500, e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package com.xuqm.im.controller;
|
||||
|
||||
import com.xuqm.common.exception.BusinessException;
|
||||
import com.xuqm.im.service.ImAccountService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class PlatformEventControllerTest {
|
||||
|
||||
@Test
|
||||
void preservesBusinessExceptionForTheSharedErrorHandler() {
|
||||
BusinessException expected = new BusinessException(404, "应用不存在");
|
||||
ImAccountService accountService = new ImAccountService(null, null, null) {
|
||||
@Override
|
||||
public String generateUserSigToken(String appKey, String userId, long expireSeconds, String userBuf) {
|
||||
throw expected;
|
||||
}
|
||||
};
|
||||
|
||||
PlatformEventController controller = new PlatformEventController(accountService);
|
||||
|
||||
BusinessException actual = assertThrows(
|
||||
BusinessException.class,
|
||||
() -> controller.token("missing-app", "platform"));
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
}
|
||||
正在加载...
在新工单中引用
屏蔽一个用户