[PR #2288] [MERGED] [EC-469] Improve ApiException message #3486

Closed
opened 2025-11-26 23:33:25 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/bitwarden/android/pull/2288
Author: @fedemkr
Created: 1/11/2023
Status: Merged
Merged: 1/12/2023
Merged by: @fedemkr

Base: masterHead: EC-469-improve-apiexception-logging


📝 Commits (2)

  • 7dc3f52 EC-469 Improve ApiException message to have the validation errors and message provided by the ErrorResponse
  • d9c73e0 EC-469 Updated default message format for ErrorResponse GetFullMessage()

📊 Changes

2 files changed (+29 additions, -0 deletions)

View changed files

📝 src/Core/Exceptions/ApiException.cs (+2 -0)
📝 src/Core/Models/Response/ErrorResponse.cs (+27 -0)

📄 Description

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Improve ApiException so that we can log an enhanced message with the errors provided by the Server instead of just "An API error has occurred"

Format that will be displayed

With ValidationErrors:

{Http status code number} {Http status code string}. [{key1}]:{validation11}; {validation12}; {validation13} ...
[{key2}]: {validation21}; {validation22}; {validation23} ...
[{key3}]:{validation31}; {validation32}; {validation33} ...
...

Without ValidationErrors:

{Http status code number} {Http status code string}. {Message}

Examples:

404 Bad Request. []: Premium status is required

404 Bad Request. [Token]: Invalid token

404 Bad Request. []: User verification failed
["MasterPassword"]: Invalid password

and if no ValidationErrors are there but there is a Message we should get something like:

403 Forbidden. You have no access to this resource

Code changes

  • ApiException: Override Message to use GetFullMessage() of the Error if possible or default to its base message
  • ErrorResponse: Added GetFullMessage() method that produces a string message based on its inner Message and ValidationErrors

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/bitwarden/android/pull/2288 **Author:** [@fedemkr](https://github.com/fedemkr) **Created:** 1/11/2023 **Status:** ✅ Merged **Merged:** 1/12/2023 **Merged by:** [@fedemkr](https://github.com/fedemkr) **Base:** `master` ← **Head:** `EC-469-improve-apiexception-logging` --- ### 📝 Commits (2) - [`7dc3f52`](https://github.com/bitwarden/android/commit/7dc3f5219c3514a7fdd1741c4adde7392490ddd3) EC-469 Improve ApiException message to have the validation errors and message provided by the ErrorResponse - [`d9c73e0`](https://github.com/bitwarden/android/commit/d9c73e0298ea9c314e927784853baf20c0fe06b6) EC-469 Updated default message format for ErrorResponse GetFullMessage() ### 📊 Changes **2 files changed** (+29 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/Core/Exceptions/ApiException.cs` (+2 -0) 📝 `src/Core/Models/Response/ErrorResponse.cs` (+27 -0) </details> ### 📄 Description ## Type of change - [ ] Bug fix - [ ] New feature development - [X] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ## Objective <!--Describe what the purpose of this PR is. For example: what bug you're fixing or what new feature you're adding--> Improve `ApiException` so that we can log an enhanced message with the errors provided by the Server instead of just "An API error has occurred" ### Format that will be displayed **With `ValidationErrors`:** {Http status code number} {Http status code string}. [{key1}]:{validation11}; {validation12}; {validation13} ... [{key2}]: {validation21}; {validation22}; {validation23} ... [{key3}]:{validation31}; {validation32}; {validation33} ... ... **Without `ValidationErrors`:** {Http status code number} {Http status code string}. {Message} **Examples:** 404 Bad Request. []: Premium status is required 404 Bad Request. [Token]: Invalid token 404 Bad Request. []: User verification failed ["MasterPassword"]: Invalid password and if no `ValidationErrors` are there but there is a `Message` we should get something like: 403 Forbidden. You have no access to this resource ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> * **ApiException:** Override `Message` to use `GetFullMessage()` of the `Error` if possible or default to its base message * **ErrorResponse:** Added `GetFullMessage()` method that produces a string message based on its inner `Message` and `ValidationErrors` ## Before you submit - Please check for formatting errors (`dotnet format --verify-no-changes`) (required) - Please add **unit tests** where it makes sense to do so (encouraged but not required) - If this change requires a **documentation update** - notify the documentation team - If this change has particular **deployment requirements** - notify the DevOps team --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-26 23:33:25 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/android#3486