Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor setting of problem detail type #4099

Merged
merged 4 commits into from Jun 21, 2023

Conversation

JohnNiang
Copy link
Member

What type of PR is this?

/kind improvement
/area core

What this PR does / why we need it:

Define a global map to mapping exception to problem detail type.

Does this PR introduce a user-facing change?

None

@f2c-ci-robot f2c-ci-robot bot added release-note-none Denotes a PR that doesn't merit a release note. kind/improvement Categorizes issue or PR as related to a improvement. labels Jun 20, 2023
@f2c-ci-robot f2c-ci-robot bot added the area/core Issues or PRs related to the Halo Core label Jun 20, 2023
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #4099 (042223d) into main (a19f342) will increase coverage by 0.21%.
The diff coverage is 89.65%.

@@             Coverage Diff              @@
##               main    #4099      +/-   ##
============================================
+ Coverage     60.23%   60.44%   +0.21%     
- Complexity     2385     2389       +4     
============================================
  Files           357      357              
  Lines         12397    12388       -9     
  Branches        892      892              
============================================
+ Hits           7467     7488      +21     
+ Misses         4493     4461      -32     
- Partials        437      439       +2     
Impacted Files Coverage Δ
...ntication/login/UsernamePasswordAuthenticator.java 43.37% <0.00%> (+5.47%) ⬆️
.../java/run/halo/app/infra/exception/Exceptions.java 96.00% <96.00%> (+96.00%) ⬆️
...ception/handlers/ProblemDetailErrorAttributes.java 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

@ruibaby
Copy link
Member

ruibaby commented Jun 20, 2023

已经触发了 Rate Limit 的情况下,当我尝试输入正确的用户名和密码后虽然也出现了异常,但刷新页面会正常跳转到 Console。

image image

@ruibaby
Copy link
Member

ruibaby commented Jun 20, 2023

测试了一下 main 分支也是这样,说明是 #4062 的问题。

@JohnNiang
Copy link
Member Author

Hi @ruibaby ,确实存在这个问题,稍后我将提交新的 PR 修复这个问题。

@guqing
Copy link
Member

guqing commented Jun 20, 2023

createErrorResponse 方法是否需要放到 Exceptions 中,我看 #4084 中有重复逻辑

@JohnNiang
Copy link
Member Author

createErrorResponse 方法是否需要放到 Exceptions 中,我看 #4084 中有重复逻辑

已抽出到 Exceptions 中。请看:3b87fc2390bb94

@JohnNiang
Copy link
Member Author

createErrorResponse 方法是否需要放到 Exceptions 中,我看 #4084 中有重复逻辑

等当前 PR 合并后,我会建议 #4084 删除对应的逻辑。因为在 HandlerFunction 中只需要抛出异常即可,会有全局异常处理器进行处理。但是登录这块儿在异常处理器之前进行的,所以只能手动调用 createErrorResponse 并写入到 ServerResponse 中。

f2c-ci-robot bot pushed a commit that referenced this pull request Jun 21, 2023
…ted (#4101)

#### What type of PR is this?

/kind bug
/area core

#### What this PR does / why we need it:

This is a bug introduced from #4062. I have overridden onAuthenticationSuccess to create rate limiter in advance instead of invoking `securityContextRepository#save` before.

See #4099 (comment) for more.

#### Special notes for your reviewer:

1. Try to log in with incorrect password three times
2. Log in with correct password and check if the response headers contain `Set-Cookie`

#### Does this PR introduce a user-facing change?

```release-note
None
```
Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Jun 21, 2023
Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2023
@guqing
Copy link
Member

guqing commented Jun 21, 2023

@JohnNiang 有冲突需要合并

@f2c-ci-robot f2c-ci-robot bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 21, 2023
@JohnNiang
Copy link
Member Author

@JohnNiang 有冲突需要合并

Thanks for reminding me! Resolved.

Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Jun 21, 2023
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jun 21, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guqing, ruibaby

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot merged commit 5e9e875 into halo-dev:main Jun 21, 2023
4 checks passed
@JohnNiang JohnNiang deleted the refactor/set-problemdetail-type branch June 21, 2023 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants