Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Add extra fields in ServiceException #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbrt
Copy link

@llbrt llbrt commented Mar 11, 2019

The goal of these changes is to be able to add some extra fields in ServiceException, to give more details about the error. These fields may be documented by the service and used on the client side (diagnosis, help, ...).

For example, the field 'extendedHelp' in this reply

{
 "code" : 403,
 "errors" :
  [ {
    "domain" : "usageLimits",
    "message" : "User Rate Limit Exceeded. Rate of requests for user exceed configured project quota. You may consider re-evaluating expected per-user traffic to the API and adjust project quota limits accordingly. You may monitor aggregate quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?project=xyz",
    "reason" : "userRateLimitExceeded",
    "extendedHelp" : "https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?project=xyz"
  } ],
  "message" : "User Rate Limit Exceeded. Rate of requests for user exceed configured project quota. You may consider re-evaluating expected per-user traffic to the API and adjust project quota limits accordingly. You may monitor aggregate quota usage and adjust limits in the API Console: https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?project=xyz"
}

- may enhance ServiceException with extra fields
- limit values to simple objects (nor array nor collection)
- add extra fields in error body
- add unit tests
- note: add test dependency to JSONassert, license Apache 2.0
@codecov-io
Copy link

Codecov Report

Merging #182 into master will increase coverage by 0.17%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #182      +/-   ##
============================================
+ Coverage     80.06%   80.24%   +0.17%     
- Complexity     1715     1721       +6     
============================================
  Files           159      159              
  Lines          5718     5734      +16     
  Branches        754      757       +3     
============================================
+ Hits           4578     4601      +23     
+ Misses          856      849       -7     
  Partials        284      284
Impacted Files Coverage Δ Complexity Δ
.../server/spi/response/RestResponseResultWriter.java 100% <100%> (ø) 6 <0> (+1) ⬆️
...va/com/google/api/server/spi/ServiceException.java 80.35% <100%> (+17.56%) 16 <8> (+4) ⬆️
...gle/api/server/spi/response/ConflictException.java 14.28% <0%> (+14.28%) 1% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39b7374...73a2b75. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants