Skip to content

Commit

Permalink
fix(exceptions): don't let null strings leak into errors field (#3021)
Browse files Browse the repository at this point in the history
`errors` should be a meaningful message since that's what UI will show.
some parts of the code (`RetrofitExceptionHandler`) already ensure that the
message can't be null, but the default handler does not.
Adding it to the lowest level so callers don't have to worry about it
  • Loading branch information
marchello2000 committed Jul 3, 2019
1 parent e4a8d3f commit 71c688e
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.netflix.spinnaker.orca.exceptions;

import com.google.common.base.Strings;
import java.util.*;
import java.util.stream.Collectors;

/** ExceptionHandler. */
public interface ExceptionHandler {
Expand Down Expand Up @@ -90,7 +92,13 @@ static Map<String, Object> responseDetails(String error) {
static Map<String, Object> responseDetails(String error, List<String> errors) {
Map<String, Object> details = new HashMap<>();
details.put("error", error);
details.put("errors", errors == null ? Collections.emptyList() : errors);
if (errors == null) {
errors = Collections.emptyList();
}

details.put(
"errors",
errors.stream().filter(x -> !Strings.isNullOrEmpty(x)).collect(Collectors.toList()));
return details;
}
}

0 comments on commit 71c688e

Please sign in to comment.