aahmed-se commented on a change in pull request #3168: Refactor api commands
URL: https://github.com/apache/pulsar/pull/3168#discussion_r242361303
##########
File path:
pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java
##########
@@ -337,46 +334,36 @@ public Response registerFunction(final String tenant,
if
(!worker().getBrokerAdmin().namespaces().getNamespaces(tenant).contains(qualifiedNamespace))
{
log.error("{}/{}/{} Namespace {} does not exist", tenant,
namespace,
componentName, namespace);
- return
Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData("Namespace does not
exist")).build();
+ throw new RestException(Status.BAD_REQUEST, "Namespace does
not exist");
}
} catch (PulsarAdminException.NotAuthorizedException e) {
log.error("{}/{}/{} Client [{}] is not admin and authorized to
operate {} on tenant", tenant, namespace,
componentName, clientRole, componentType);
- return
Response.status(Status.UNAUTHORIZED).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData("client is not authorize to perform
operation")).build();
-
+ throw new RestException(Status.UNAUTHORIZED, "client is not
authorize to perform operation");
} catch (PulsarAdminException.NotFoundException e) {
- log.error("{}/{}/{} Tenant {} does not exist", tenant, namespace,
- componentName, tenant);
- return
Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData("Tenant does not exist")).build();
+ log.error("{}/{}/{} Tenant {} does not exist", tenant, namespace,
componentName, tenant);
+ throw new RestException(Status.BAD_REQUEST, "Tenant does not
exist");
} catch (PulsarAdminException e) {
- log.error("{}/{}/{} Issues getting tenant data", tenant, namespace,
- componentName, e);
- return
Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData(e.getMessage())).build();
+ log.error("{}/{}/{} Issues getting tenant data", tenant,
namespace, componentName, e);
+ throw new RestException(Status.INTERNAL_SERVER_ERROR,
e.getMessage());
}
try {
if (!isAuthorizedRole(tenant, clientRole)) {
log.error("{}/{}/{} Client [{}] is not admin and authorized to
register {}", tenant, namespace,
componentName, clientRole, componentType);
- return
Response.status(Status.UNAUTHORIZED).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData("client is not authorize to
perform operation")).build();
+ throw new RestException(Status.UNAUTHORIZED, "client is not
authorize to perform operation");
}
} catch (PulsarAdminException e) {
log.error("{}/{}/{} Failed to authorize [{}]", tenant, namespace,
componentName, e);
- return
Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData(e.getMessage())).build();
+ throw new RestException(Status.INTERNAL_SERVER_ERROR,
e.getMessage());
}
FunctionMetaDataManager functionMetaDataManager =
worker().getFunctionMetaDataManager();
if (functionMetaDataManager.containsFunction(tenant, namespace,
componentName)) {
log.error("{} {}/{}/{} already exists", componentType, tenant,
namespace, componentName);
- return
Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON)
- .entity(new ErrorData(String.format("%s %s already
exists", componentType, componentName))).build();
+ throw new RestException(Status.INTERNAL_SERVER_ERROR,
String.format("%s %s already exists", componentType, componentName));
Review comment:
reverted the error code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services