api server exception management and code optimization (#397)#2397
api server exception management and code optimization (#397)#2397davidzollo merged 4 commits intoapache:devfrom hgaol:dev
Conversation
|
Hi, is there anyone can help me on the unit test issue? How could I do to solve it... To this situation. @dailidong |
|
good job, the code becomes more concise. I think you can refer the QueueControllerTest , about Exception Test , refer the following code: I want to say I'm not very familar with MockMvc, you can contact me by mail( lidongdai@apache.org ) or add my wechat(510570367), when added , please tell me your github id is hgaol |
OK, let me have a try. thank you! |
Codecov Report
@@ Coverage Diff @@
## dev #2397 +/- ##
============================================
+ Coverage 32.81% 32.91% +0.09%
- Complexity 2268 2276 +8
============================================
Files 422 423 +1
Lines 19830 19839 +9
Branches 2363 2366 +3
============================================
+ Hits 6508 6530 +22
+ Misses 12741 12725 -16
- Partials 581 584 +3
Continue to review full report at Codecov.
|
|
I've added some tests, but seems it doesn't run. Does anyone has some ideas on that? |
|
At last, it works, thanks @dailidong for your help. |
...nscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AccessTokenService.java
Outdated
Show resolved
Hide resolved
...heduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ApiServerException.java
Outdated
Show resolved
Hide resolved
...eduler-api/src/main/java/org/apache/dolphinscheduler/api/exceptions/ControllerException.java
Outdated
Show resolved
Hide resolved
|
Kudos, SonarCloud Quality Gate passed!
|
|
good job. thanks for your first contribution, looking forward for your next conttribution, haha |
Tips
What is the purpose of the pull request
Currently, there are many
try-catchcode inapi-server's controller. This pr clean the code, use an annotation to point out whichStatusshould be return if there is an exception.I just update
AccessTokenControllerfirstly, to avoid conflict. If this PR is accepted, maybe I could update for other controllers :)i.e.
Before
After
Brief change log
ControllerExceptionannotation inorg.apache.dolphinscheduler.api.exceptions.ApiExceptionHandlercontroller advice to deal with exceptions.AccessTokenControllerfunctions which hastry-catchstyle with@ControllerExceptionannotation.Verify this pull request
I've debugged the code locally, and it works well. But it's difficult to write tests for this code, because I should find how to throw an exception. It will be easy if I can write some test controllers to test this PR. Pls tell me if I can do that, or is there any other way for testing.
Thanks in advance!
Hope it has no conflict.