-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK-2352: Enhanced error reason #421
Conversation
8cd75a9
to
be5b151
Compare
67e12c1
to
d5d68fc
Compare
yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityFailureException.java
Outdated
Show resolved
Hide resolved
...ing-boot-example/src/main/java/com/yoti/api/examples/springboot/IdentityLoginController.java
Outdated
Show resolved
Hide resolved
...g-boot-example/src/main/java/com/yoti/api/examples/springboot/IdentitySessionController.java
Show resolved
Hide resolved
...ing-boot-example/src/main/java/com/yoti/api/examples/springboot/IdentityLoginController.java
Outdated
Show resolved
Hide resolved
String.format("Error[code='%s' description='%s' reason='%s']", | ||
e.getCode(), | ||
e.getDescription(), | ||
e.getReason() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like what the implementation fo toString()
should look like... as in:
Optional.ofNullable(profile.getError())
.map(ErrorDetails::toString)
.orElse("")
@JsonProperty(Property.REASON) | ||
public Builder reason(Map<String, Object> reason) { | ||
try { | ||
this.reason = new ObjectMapper().writeValueAsString(reason); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to create an ObjectMapper
instance every time we de-serialize a JSON. Make it a constant (maybe even a "global" constant if it's important to enforce the same config wherever it is used).
try { | ||
this.reason = new ObjectMapper().writeValueAsString(reason); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("The reason of the failed share has an unexpected format"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually an exception message will say:
- What failed
- Why it failed
- (optional) what it would take to not fail
So something like:
String.format("Failed to parse failure receipt error reason: '%s'", e.getMessage())
Additionally it's not a very good practice to swallow exceptions like this. Either pass the exception as a cause or include the message of the exception when creating the message for the exception that will be (re)thrown.
(a third option would be to log the stack trace and not propagate the cause, however it would require a logging framework which I don't know if this has)
When it comes to including the message it might also be useful to include every message along the exception chain (in case there's more than one cause) along the lines of:
<ex msg>: <msg of cause of ex>: <msg of cause of cause of ex>
(this comment applies elsewhere where the same pattern exists)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up creating an exception for it
@@ -65,10 +67,18 @@ public UserContent getUserContent() { | |||
return userContent; | |||
} | |||
|
|||
public boolean hasError() { | |||
return getError().isPresent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid calling methods within a class that will only access member variables. Whenever you need to use a member var just use the member var:
return error != null
8367d11
to
abe861e
Compare
abe861e
to
e5a5b32
Compare
...ing-boot-example/src/main/java/com/yoti/api/examples/springboot/IdentityLoginController.java
Outdated
Show resolved
Hide resolved
e5a5b32
to
8cce312
Compare
Kudos, SonarCloud Quality Gate passed! |
No description provided.