Search in sources :

Example 46 with NotFoundException

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;
}
Also used : SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException)

Example 47 with NotFoundException

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();
}
Also used : SourceLocation(graphql.language.SourceLocation) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) GraphQLError(graphql.GraphQLError) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) GraphqlErrorBuilder(graphql.GraphqlErrorBuilder) ExecutionPath(graphql.execution.ExecutionPath)

Aggregations

NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)47 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)26 ApiOperation (io.swagger.annotations.ApiOperation)19 NotNull (org.jetbrains.annotations.NotNull)14 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)13 ServiceLocator (jetbrains.buildServer.ServiceLocator)10 SUser (jetbrains.buildServer.users.SUser)10 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)10 Nullable (org.jetbrains.annotations.Nullable)8 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)7 AuthorizationFailedException (jetbrains.buildServer.server.rest.errors.AuthorizationFailedException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 Converter (jetbrains.buildServer.util.Converter)4 RevisionsNotFoundException (jetbrains.buildServer.vcs.impl.RevisionsNotFoundException)4 Logger (com.intellij.openapi.diagnostic.Logger)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 SUserGroup (jetbrains.buildServer.groups.SUserGroup)3 SArtifactDependency (jetbrains.buildServer.serverSide.artifacts.SArtifactDependency)3 Permission (jetbrains.buildServer.serverSide.auth.Permission)3