Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'chore/improve-error-messages' into feat/add_slack_notif…
Browse files Browse the repository at this point in the history
…ications
  • Loading branch information
tunderwood committed Sep 25, 2020
2 parents b4d9bbe + 8583de9 commit a96e1be
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.nike.backstopper.exception.ApiException;
import com.nike.cerberus.error.DefaultApiError;
import com.nike.cerberus.util.CustomApiError;
import com.okta.sdk.clients.UserGroupApiClient;
import com.okta.sdk.framework.ApiClientConfiguration;
import com.okta.sdk.framework.PagedResults;
Expand Down Expand Up @@ -99,7 +100,8 @@ protected List<UserGroup> getUserGroups(String userId, Integer limit) {
"failed to get user groups for user (%s) for reason: %s", userId, ioe.getMessage());

throw ApiException.newBuilder()
.withApiErrors(DefaultApiError.GENERIC_BAD_REQUEST)
.withApiErrors(
CustomApiError.createCustomApiError(DefaultApiError.GENERIC_BAD_REQUEST, msg))
.withExceptionMessage(msg)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.nike.backstopper.apierror.ApiErrorBase;
import com.nike.backstopper.exception.ApiException;
import com.nike.cerberus.auth.connector.AuthData;
import com.nike.cerberus.auth.connector.AuthResponse;
import com.nike.cerberus.auth.connector.AuthStatus;
import com.nike.cerberus.error.DefaultApiError;
import com.nike.cerberus.util.CustomApiError;
import com.okta.authn.sdk.AuthenticationStateHandlerAdapter;
import com.okta.authn.sdk.client.AuthenticationClient;
import com.okta.authn.sdk.resource.AuthenticationResponse;
Expand Down Expand Up @@ -204,12 +204,8 @@ public void handleUnknown(AuthenticationResponse typedUnknownResponse) {
}

throw ApiException.newBuilder()
.withApiErrors(
new ApiErrorBase(
DefaultApiError.AUTH_FAILED.getName(),
DefaultApiError.AUTH_FAILED.getErrorCode(),
message,
DefaultApiError.AUTH_FAILED.getHttpStatusCode()))
.withApiErrors(CustomApiError.createCustomApiError(DefaultApiError.AUTH_FAILED, message))
.withExceptionMessage(message)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020 Nike, inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.nike.cerberus.util;

import com.nike.backstopper.apierror.ApiError;
import com.nike.backstopper.apierror.ApiErrorBase;
import com.nike.cerberus.error.DefaultApiError;
import java.util.UUID;

public final class CustomApiError {

public static ApiError createCustomApiError(DefaultApiError error, final String message) {
return new ApiErrorBase(
"custom-error-wrapper-" + UUID.randomUUID().toString(),
error.getErrorCode(),
error.getMessage() + " " + message,
error.getHttpStatusCode());
}
}
Loading

0 comments on commit a96e1be

Please sign in to comment.