Skip to content

Commit

Permalink
Add errorCode to failure type InternalServerError (#16186)
Browse files Browse the repository at this point in the history
Changes:
- Use error code `internalServerError` for failures of this type
- Remove the error code argument from `InternalServerError.exception()` methods
thus fixing a bug in the callers.
  • Loading branch information
kfaraz committed Mar 23, 2024
1 parent cfa2a90 commit 323d67a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ private Task toTaskUsingDeepStorage(Job from) throws IOException
com.google.common.base.Optional<InputStream> taskBody = taskLogs.streamTaskPayload(getTaskId(from).getOriginalTaskId());
if (!taskBody.isPresent()) {
throw InternalServerError.exception(
"Could not load task payload from deep storage for job [%s]. Check the overlord logs for any errors in uploading task payload to deep storage.",
"Could not load task payload from deep storage for job [%s]."
+ " Check the overlord logs for any errors in uploading task payload to deep storage.",
from.getMetadata().getName()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ private Task toTaskUsingDeepStorage(Job from) throws IOException
com.google.common.base.Optional<InputStream> taskBody = taskLogs.streamTaskPayload(getTaskId(from).getOriginalTaskId());
if (!taskBody.isPresent()) {
throw InternalServerError.exception(
"Could not load task payload from deep storage for job [%s]. Check the overlord logs for errors uploading task payloads to deep storage.",
"Could not load task payload from deep storage for job [%s]."
+ " Check the overlord logs for errors uploading task payloads to deep storage.",
from.getMetadata().getName()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@

public class InternalServerError extends BaseFailure
{
public static DruidException exception(String errorCode, String msg, Object... args)
public static DruidException exception(String msg, Object... args)
{
return exception(null, errorCode, msg, args);
return exception(null, msg, args);
}

public static DruidException exception(Throwable t, String errorCode, String msg, Object... args)
public static DruidException exception(Throwable t, String msg, Object... args)
{
return DruidException.fromFailure(new InternalServerError(t, errorCode, msg, args));
return DruidException.fromFailure(new InternalServerError(t, msg, args));
}

private InternalServerError(
Throwable t,
String errorCode,
String msg,
Object... args
)
{
super(
errorCode,
"internalServerError",
DruidException.Persona.OPERATOR,
DruidException.Category.RUNTIME_FAILURE,
t, msg, args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public class InternalServerErrorTest
@Test
public void testAsErrorResponse()
{
ErrorResponse errorResponse = new ErrorResponse(InternalServerError.exception("runtimeFailure", "Internal Server Error"));
ErrorResponse errorResponse = new ErrorResponse(InternalServerError.exception("Internal Server Error"));
final Map<String, Object> asMap = errorResponse.getAsMap();

MatcherAssert.assertThat(
asMap,
DruidMatchers.mapMatcher(
"error", "druidException",
"errorCode", "runtimeFailure",
"errorCode", "internalServerError",
"persona", "OPERATOR",
"category", "RUNTIME_FAILURE",
"errorMessage", "Internal Server Error"
Expand All @@ -52,7 +52,7 @@ public void testAsErrorResponse()
new DruidExceptionMatcher(
DruidException.Persona.OPERATOR,
DruidException.Category.RUNTIME_FAILURE,
"runtimeFailure"
"internalServerError"
).expectMessageContains("Internal Server Error")
);
}
Expand Down

0 comments on commit 323d67a

Please sign in to comment.