Skip to content

Commit

Permalink
fix: interceptor config. feat: better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ballade0d committed Oct 19, 2024
1 parent d671e21 commit 1878816
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
11 changes: 0 additions & 11 deletions src/main/java/fun/sast/evento/lark/api/security/Permission.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package fun.sast.evento.lark.api.security;

import fun.sast.evento.lark.infrastructure.error.BusinessException;
import fun.sast.evento.lark.infrastructure.error.ErrorEnum;
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum Permission {
LOGIN(0),
Expand All @@ -18,11 +14,4 @@ public enum Permission {
Permission(int num) {
this.num = num;
}

public Permission getPermissionByNum(int num) {
return Arrays.stream(Permission.values())
.filter(permission -> permission.num == num)
.findAny()
.orElseThrow(() -> new BusinessException(ErrorEnum.DEFAULT, "permission not exist"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<LarkRoom> list() {
.build());
if (!resp.success()) {
log.error("failed to list room: {}", resp.getMsg());
throw new BusinessException(ErrorEnum.LARK_ERROR, resp.getMsg());
throw new BusinessException(ErrorEnum.LARK_ERROR_LIST_ROOM, resp.getMsg());
}
if (resp.getData().getRooms() != null) {
Arrays.stream(resp.getData().getRooms()).forEach(room -> larkRooms.add(new LarkRoom(
Expand All @@ -60,8 +60,8 @@ public List<LarkRoom> list() {
} while (hasMore);
return larkRooms;
} catch (Exception e) {
log.error("list room error", e);
throw new BusinessException(ErrorEnum.LARK_ERROR, e.getMessage());
log.error("list room error: {}", e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}

Expand All @@ -73,16 +73,16 @@ public LarkRoom get(String id) {
.build());
if (!resp.success()) {
log.error("failed to get room: {}", resp.getMsg());
throw new BusinessException(ErrorEnum.LARK_ERROR, resp.getMsg());
throw new BusinessException(ErrorEnum.LARK_ERROR_GET_ROOM, resp.getMsg());
}
return new LarkRoom(
resp.getData().getRoom().getRoomId(),
resp.getData().getRoom().getName(),
resp.getData().getRoom().getCapacity()
);
} catch (Exception e) {
log.error("get room error", e);
throw new BusinessException(ErrorEnum.LARK_ERROR, e.getMessage());
log.error("get room error: {}", e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}

Expand All @@ -104,12 +104,12 @@ public Boolean isAvailable(String id, LocalDateTime start, LocalDateTime end) {
return node.get("data").get("free_busy").isEmpty();
} else {
log.error("failed to check room availability: {}", msg);
throw new BusinessException(ErrorEnum.LARK_ERROR, msg);
throw new BusinessException(ErrorEnum.LARK_ERROR_CHECK_ROOM_AVAILABLE, msg);

}
} catch (Exception e) {
log.error("check room availability error", e);
throw new BusinessException(ErrorEnum.LARK_ERROR, e.getMessage());
log.error("check room availability error: {}", e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor)
//TODO delete after test
// .addPathPatterns("/**")
.excludePathPatterns("/api/login/**");
.excludePathPatterns("/api/v2/login/**");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public enum ErrorEnum {
LARK_ERROR_LIST_DEPARTMENT(2010, "Failed to list department"),
LARK_ERROR_GET_DEPARTMENT(2011, "Failed to get department"),
LARK_ERROR_GET_DEPARTMENT_USER(2012, "Failed to get user list"),
LARK_ERROR_LIST_ROOM(2013, "Failed to list room"),
LARK_ERROR_GET_ROOM(2014, "Failed to get room"),
LARK_ERROR_CHECK_ROOM_AVAILABLE(2015, "Failed to check room available"),

FEEDBACK_ALREADY_GIVEN(3001, "You have already given feedback for this event"),
;
Expand Down

0 comments on commit 1878816

Please sign in to comment.