Skip to content

Commit

Permalink
Improve SubscriptionBlockedException error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishka-Shamendra committed Mar 12, 2024
1 parent a130b0c commit 6072f21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.wso2.carbon.apimgt.api.APIMgtAuthorizationFailedException;
import org.wso2.carbon.apimgt.api.MonetizationException;
import org.wso2.carbon.apimgt.api.SubscriptionAlreadyExistingException;
import org.wso2.carbon.apimgt.api.SubscriptionBlockedException;
import org.wso2.carbon.apimgt.api.WorkflowResponse;
import org.wso2.carbon.apimgt.api.WorkflowStatus;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
Expand Down Expand Up @@ -247,6 +248,9 @@ public Response subscriptionsPost(SubscriptionDTO body, String xWSO2Tenant, Mess
RestApiUtil.handleResourceAlreadyExistsError(
"Specified subscription already exists for API " + body.getApiId() + ", for application "
+ body.getApplicationId(), e, log);
} catch (SubscriptionBlockedException e) {
RestApiUtil.handleOperationBlockedError("Subscription blocked. " + e.getMessage()
+ ". Please contact the API publisher.", e, log);
} catch (URISyntaxException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
//this happens when the specified API identifier does not exist
Expand Down Expand Up @@ -350,6 +354,9 @@ public Response subscriptionsSubscriptionIdPut(String subscriptionId, Subscripti
RestApiUtil.handleResourceAlreadyExistsError(
"Specified subscription already exists for API " + body.getApiId() + ", for application "
+ body.getApplicationId(), e, log);
} catch (SubscriptionBlockedException e) {
RestApiUtil.handleOperationBlockedError("Subscription blocked. " + e.getMessage()
+ ". Please contact the API publisher.", e, log);
} catch (APIManagementException | URISyntaxException e) {
if (RestApiUtil.isDueToResourceNotFound(e)) {
//this happens when the specified API identifier does not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,20 @@ public static void handleInternalServerError(String msg, Log log)
throw internalServerErrorException;
}

/**
* Logs the error, builds a ForbiddenException with specified details and throws it
* @param msg error message
* @param t Throwable instance
* @param log Log instance
* @throws ForbiddenException
*/
public static void handleOperationBlockedError(String msg, Throwable t, Log log)
throws ForbiddenException{
ForbiddenException forbiddenException = buildForbiddenException(msg);
log.error(msg,t);
throw forbiddenException;
}

/**
* Check whether the HTTP method is allowed for given resources
*
Expand Down

0 comments on commit 6072f21

Please sign in to comment.