Skip to content

Commit

Permalink
feat: 优化 API 错误信息
Browse files Browse the repository at this point in the history
  • Loading branch information
FHU-yezi committed Feb 20, 2024
1 parent 2a68731 commit 96a0e74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions backend/api/v1/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def get_word_freq_handler(
article_slug: Annotated[
str,
Parameter(
description="文章 slug",
description="文章 Slug",
min_length=12,
max_length=12,
examples=[
Expand All @@ -160,7 +160,7 @@ async def get_word_freq_handler(
return fail(
http_code=HTTP_400_BAD_REQUEST,
api_code=Code.BAD_ARGUMENTS,
msg="文章 slug 无效",
msg="文章 Slug 无效",
)
except ResourceUnavailableError:
return fail(
Expand Down Expand Up @@ -202,7 +202,7 @@ async def get_LP_recommend_check_handler( # noqa: N802
article_slug: Annotated[
str,
Parameter(
description="文章 slug",
description="文章 Slug",
min_length=12,
max_length=12,
examples=[
Expand All @@ -221,7 +221,7 @@ async def get_LP_recommend_check_handler( # noqa: N802
return fail(
http_code=HTTP_400_BAD_REQUEST,
api_code=Code.BAD_ARGUMENTS,
msg="文章 slug 无效",
msg="文章 Slug 无效",
)
except ResourceUnavailableError:
return fail(
Expand Down
16 changes: 8 additions & 8 deletions backend/api/v1/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GetVipInfoResponse(Struct, **RESPONSE_STRUCT_CONFIG):
)
async def get_vip_info_handler(
user_slug: Annotated[
str, Parameter(description="用户 slug", min_length=6, max_length=12)
str, Parameter(description="用户 Slug", min_length=6, max_length=12)
],
) -> Response:
try:
Expand All @@ -45,7 +45,7 @@ async def get_vip_info_handler(
return fail(
http_code=HTTP_400_BAD_REQUEST,
api_code=Code.BAD_ARGUMENTS,
msg="用户 slug 无效",
msg="用户 Slug 无效",
)
except ResourceUnavailableError:
return fail(
Expand Down Expand Up @@ -91,7 +91,7 @@ class GetLotteryWinRecordsResponse(Struct, **RESPONSE_STRUCT_CONFIG):
)
async def get_lottery_win_records(
user_slug: Annotated[
str, Parameter(description="用户 slug", min_length=6, max_length=12)
str, Parameter(description="用户 Slug", min_length=6, max_length=12)
],
offset: Annotated[int, Parameter(description="分页偏移", ge=0)] = 0,
limit: Annotated[int, Parameter(description="结果数量", gt=0, lt=100)] = 20,
Expand All @@ -105,7 +105,7 @@ async def get_lottery_win_records(
return fail(
http_code=HTTP_400_BAD_REQUEST,
api_code=Code.BAD_ARGUMENTS,
msg="用户 slug 无效",
msg="用户 Slug 无效",
)

result = (
Expand Down Expand Up @@ -158,7 +158,7 @@ class GetOnArticleRankRecordsResponse(Struct, **RESPONSE_STRUCT_CONFIG):
)
async def get_on_article_rank_records_handler(
user_slug: Annotated[
str, Parameter(description="用户 slug", min_length=6, max_length=12)
str, Parameter(description="用户 Slug", min_length=6, max_length=12)
],
order_by: Annotated[
Literal["date", "ranking"], Parameter(description="排序依据")
Expand All @@ -175,7 +175,7 @@ async def get_on_article_rank_records_handler(
return fail(
http_code=HTTP_400_BAD_REQUEST,
api_code=Code.BAD_ARGUMENTS,
msg="用户 slug 无效",
msg="用户 Slug 无效",
)

result = (
Expand Down Expand Up @@ -264,7 +264,7 @@ class GetOnArticleRankSummaryResponse(Struct, **RESPONSE_STRUCT_CONFIG):
)
async def get_on_article_rank_summary_handler(
user_slug: Annotated[
str, Parameter(description="用户 slug", min_length=6, max_length=12)
str, Parameter(description="用户 Slug", min_length=6, max_length=12)
],
) -> Response:
try:
Expand All @@ -273,7 +273,7 @@ async def get_on_article_rank_summary_handler(
return fail(
http_code=HTTP_400_BAD_REQUEST,
api_code=Code.BAD_ARGUMENTS,
msg="用户 slug 无效",
msg="用户 Slug 无效",
)

records = ARTICLE_FP_RANK_COLLECTION.find(
Expand Down

0 comments on commit 96a0e74

Please sign in to comment.