question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotation to specify multiple UnexpectedResponseExceptionType

See original GitHub issue

Is your feature request related to a problem? Please describe. The REST Proxy should be able to throw richer exception depending on the error code returned by service.

Describe the solution you’d like Define an annotation, that can be used to define multiple exception types and map each exception type to error codes.

An example usage looks like:

@UnexpectedResponseExceptionTypes({ @UnexpectedResponseExceptionTypes.Type(code = {333}, value = Exception333.class), @UnexpectedResponseExceptionTypes.Type(code = {345, 346}, value = RestException.class), @UnexpectedResponseExceptionTypes.Type(value = ServiceRequestException.class) })

The annotation looks like:

public @interface UnexpectedResponseExceptionTypes { public Type[] value();

public @interface Type { public int[] code() default { }; public Class<?> value(); } }

The above grouping is needed only in java 7 and below, java 8+ supports repeated annotations. Switching to the experience that @JonathanGiles originally proposed.

Reference: see this discussion.

Example usage:

@UnexpectedResponseExceptionType(code = {333}, value = Exception333.class),
@UnexpectedResponseExceptionType(code = {345, 346}, value = RestException.class),
@UnexpectedResponseExceptionType(value = ServiceRequestException.class)

Annotation definition:

public @interface UnexpectedResponseExceptionType {
    public Class<?> value();
    public int[] code() default { };
}

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Description Added
  • Expected solution specified

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

0reactions
JonathanGilescommented, Apr 9, 2019

@jianghaolu will work on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnexpectedResponseException...
The exception type that is thrown or returned when one of the status codes is returned from a REST API. Multiple annotations can...
Read more >
DirectorysImpl.java - com.azure.storage.file.implementation - NET
import com.azure.core.annotation.Delete; ... @UnexpectedResponseExceptionType(StorageErrorException.class) ... For more information, see <a ...
Read more >
com.microsoft.rest.v2.annotations.GET java code examples | Tabnine
@GET("") @ExpectedResponses({200}) @UnexpectedResponseExceptionType(StorageErrorException.class) Single<ServiceGetStatisticsResponse> getStatistics(Context ...
Read more >
java - Multiple annotations of the same type on one element?
I can either specify @Index twice with different expr() values, or take the approach specified in the accepted answer. Even though Hibernate does...
Read more >
Index (azure-core-rest 1.0.0-beta.10 API)
Annotation to annotate a parameter to send to a REST endpoint as HTTP Request ... Get the generic argument, or the first if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found