Skip to content

Commit

Permalink
Merge pull request #12299 from Avishka-Shamendra/fix-internal-5632
Browse files Browse the repository at this point in the history
Improve SubscriptionBlockedException Error Handling
  • Loading branch information
tharikaGitHub authored Mar 22, 2024
2 parents 691e8e3 + 922dcab commit c748533
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 c748533

Please sign in to comment.