Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,6 @@ public ExceptionDetailsStage<T> message(Supplier<String> messageSupplier) {
return this;
}

/**
* Throws the configured exception if the specified condition is true.
* This is a convenience method for conditional exception throwing.
*
* @param condition the condition to evaluate
* @throws T the configured exception if the condition is true
*/
@Override
public void throwIf(boolean condition) throws T {
if (condition) {
throw exception();
}
}

/**
* Creates and returns the exception instance with all configured properties.
* If no message was set, use the default message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ public interface ExceptionDetailsStage<T extends Throwable> {
ExceptionDetailsStage<T> message(Supplier<String> messageSupplier);

T exception();

void throwIf(boolean condition) throws T;
}
14 changes: 8 additions & 6 deletions src/main/java/com/ziro/espresso/okhttp3/JwtTokenFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ public static String createAccessToken(String scope, String clientId, String cli
ResponseBody responseBody = Objects.requireNonNull(response.body(), "responseBody should not be null");
String responseAsString = new String(responseBody.bytes());

SystemUnhandledException.asRootCause()
.message(
"Failed to obtain access token from Authorization Server. "
+ "The Authorization Server returned [status_code=%s, response=%s].",
response.code(), responseAsString)
.throwIf(response.code() != SUCCESS_STATUS_CODE);
if (response.code() != SUCCESS_STATUS_CODE) {
throw SystemUnhandledException.asRootCause()
.message(
"Failed to obtain access token from Authorization Server. "
+ "The Authorization Server returned [status_code=%s, response=%s].",
response.code(), responseAsString)
.exception();
}

JsonNode jwtJsonObject = OBJECT_MAPPER.readTree(responseAsString);
return jwtJsonObject.get("access_token").asText();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ziro.espresso.fluent.exceptions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -29,20 +28,6 @@ void whenUsingAsRootCauseThenExceptionHasNoCause() {
assertThat(exception.getCause()).isNull();
}

@Test
void whenUsingWithCauseAndThrowIfThenThrowsExceptionWhenConditionTrue() {
RuntimeException originalCause = new RuntimeException("Original error");

assertThatThrownBy(() -> {
SystemUnhandledException.withCause(originalCause)
.message("Something went wrong")
.throwIf(true);
})
.isInstanceOf(SystemUnhandledException.class)
.hasMessage("Something went wrong")
.hasCause(originalCause);
}

@Test
void whenUsingMessageWithFormatting_thenFormatsCorrectly() {
SystemUnhandledException exception = SystemUnhandledException.asRootCause()
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
6.0.0