use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class AgentFinder method getAgentType.
public static SAgentType getAgentType(@NotNull final String agentTypeLocator, @NotNull final AgentTypeFinder agentTypeFinder) {
// support only int single value for now
Integer agentTypeId = null;
try {
agentTypeId = Integer.valueOf(agentTypeLocator);
} catch (NumberFormatException e) {
throw new BadRequestException("Bad agent type id '" + agentTypeLocator + "': should be a number");
}
// make AgentFinder finding agent types in the future
SAgentType agentType = agentTypeFinder.findAgentType(agentTypeId);
if (agentType == null) {
throw new NotFoundException("No agent type is found by id '" + agentTypeId + "'");
}
return agentType;
}
use of jetbrains.buildServer.server.rest.errors.NotFoundException in project teamcity-rest by JetBrains.
the class ResolverExceptionHandler method onException.
@Override
public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandlerParameters handlerParameters) {
Throwable exception = handlerParameters.getException();
SourceLocation sourceLocation = handlerParameters.getSourceLocation();
ExecutionPath path = handlerParameters.getPath();
GraphqlErrorBuilder builder = GraphqlErrorBuilder.newError().path(path).location(sourceLocation);
if (exception.getMessage() != null) {
builder.message(exception.getMessage());
} else {
builder.message(exception.getClass().getSimpleName());
}
if (exception instanceof AccessDeniedException) {
GraphQLError error = builder.errorType(TeamCityGraphQLErrorType.ACCESS_DENIED).build();
return DataFetcherExceptionHandlerResult.newResult().error(error).build();
}
if (exception instanceof NotFoundException) {
GraphQLError error = builder.errorType(TeamCityGraphQLErrorType.NOT_FOUND).build();
return DataFetcherExceptionHandlerResult.newResult().error(error).build();
}
LOG.warnAndDebugDetails("Exception occured while fetching data.", exception);
GraphQLError error = builder.errorType(TeamCityGraphQLErrorType.SERVER_ERROR).build();
return DataFetcherExceptionHandlerResult.newResult().error(error).build();
}
Aggregations