eclipse / kapua

Eclipse Public License 2.0
227 stars 160 forks source link

🐛 [REST API] Make DuplicateNameException return `409` HTTP error code #4133

Closed MDeLuise closed 1 week ago

MDeLuise commented 2 weeks ago

Summary

This PR addresses the issue where creating an entity with a duplicate name resulted in a 500 HTTP error. The error handling has been updated to return a 409 HTTP error code, which is more appropriate for this scenario.

Changes Made

New Response Structure

The new response for a duplicate entity creation will be as follows:

{
  "type": "duplicateNameExceptionInfo",
  "httpErrorCode": 409,
  "message": "An entity with the same name <name> already exists.",
  "kapuaErrorCode": "DUPLICATE_NAME",
  "duplicatedName": "<name>"
}

Steps to Reproduce

  1. Create a new named entity (e.g., Role).
  2. Attempt to create another named entity with the same name.
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Project coverage is 16.80%. Comparing base (a94041c) to head (fa8df3a). Report is 27 commits behind head on develop.

Files with missing lines Patch % Lines
...rest/errors/KapuaDuplicateNameExceptionMapper.java 0.00% 9 Missing :warning:
.../rest/model/errors/DuplicateNameExceptionInfo.java 0.00% 6 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/eclipse/kapua/pull/4133/graphs/tree.svg?width=650&height=150&src=pr&token=1P4N4CApH8&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse)](https://app.codecov.io/gh/eclipse/kapua/pull/4133?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse) ```diff @@ Coverage Diff @@ ## develop #4133 +/- ## ========================================== Coverage 16.80% 16.80% Complexity 22 22 ========================================== Files 2021 2023 +2 Lines 52468 52486 +18 Branches 4425 4426 +1 ========================================== + Hits 8815 8820 +5 - Misses 43255 43268 +13 Partials 398 398 ``` | [Files with missing lines](https://app.codecov.io/gh/eclipse/kapua/pull/4133?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse) | Coverage Δ | | |---|---|---| | [.../rest/model/errors/DuplicateNameExceptionInfo.java](https://app.codecov.io/gh/eclipse/kapua/pull/4133?src=pr&el=tree&filepath=commons-rest%2Fmodel%2Fsrc%2Fmain%2Fjava%2Forg%2Feclipse%2Fkapua%2Fcommons%2Frest%2Fmodel%2Ferrors%2FDuplicateNameExceptionInfo.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse#diff-Y29tbW9ucy1yZXN0L21vZGVsL3NyYy9tYWluL2phdmEvb3JnL2VjbGlwc2Uva2FwdWEvY29tbW9ucy9yZXN0L21vZGVsL2Vycm9ycy9EdXBsaWNhdGVOYW1lRXhjZXB0aW9uSW5mby5qYXZh) | `0.00% <0.00%> (ø)` | | | [...rest/errors/KapuaDuplicateNameExceptionMapper.java](https://app.codecov.io/gh/eclipse/kapua/pull/4133?src=pr&el=tree&filepath=commons-rest%2Ferrors%2Fsrc%2Fmain%2Fjava%2Forg%2Feclipse%2Fkapua%2Fcommons%2Frest%2Ferrors%2FKapuaDuplicateNameExceptionMapper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse#diff-Y29tbW9ucy1yZXN0L2Vycm9ycy9zcmMvbWFpbi9qYXZhL29yZy9lY2xpcHNlL2thcHVhL2NvbW1vbnMvcmVzdC9lcnJvcnMvS2FwdWFEdXBsaWNhdGVOYW1lRXhjZXB0aW9uTWFwcGVyLmphdmE=) | `0.00% <0.00%> (ø)` | | ... and [5 files with indirect coverage changes](https://app.codecov.io/gh/eclipse/kapua/pull/4133/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse)

🚨 Try these New Features: