Search in sources :

Example 1 with BadRequestException

use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.

the class ApiController method getCursor.

protected long getCursor(Request request, String key) {
    long cursor = 0;
    try {
        String value = request.queryParams(key);
        if (isBlank(value)) {
            return cursor;
        }
        cursor = Long.parseLong(value);
    } catch (NumberFormatException nfe) {
        throw new BadRequestException(String.format(BAD_CURSOR_MSG, key));
    }
    return cursor;
}
Also used : BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Example 2 with BadRequestException

use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.

the class BuildCauseController method index.

public String index(Request req, Response res) throws IOException {
    HttpOperationResult httpOperationResult = new HttpOperationResult();
    int result;
    try {
        result = Integer.parseInt(req.params(":pipeline_counter"));
    } catch (NumberFormatException nfe) {
        throw new BadRequestException("Parameter `pipeline_counter` must be an integer.");
    }
    String pipelineName = req.params("pipeline_name");
    PipelineInstanceModel pipelineInstance = pipelineHistoryService.findPipelineInstance(pipelineName, result, currentUsername(), httpOperationResult);
    if (httpOperationResult.isSuccess()) {
        return writerForTopLevelObject(req, res, outputWriter -> BuildCauseRepresenter.toJSON(outputWriter, pipelineInstance.getBuildCause()));
    } else {
        return renderHTTPOperationResult(httpOperationResult, req, res);
    }
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Example 3 with BadRequestException

use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.

the class BackupsControllerV2 method show.

public String show(Request request, Response response) throws IOException {
    String backupId = request.params("id");
    Optional<ServerBackup> backup;
    if (RUNNING.equals(backupId)) {
        backup = backupService.runningBackup();
    } else {
        try {
            backup = backupService.getServerBackup(Long.parseLong(backupId));
        } catch (NumberFormatException e) {
            throw new BadRequestException("The `id` parameter should be a number, or the keyword `running`");
        }
    }
    if (!backup.isPresent()) {
        throw new RecordNotFoundException(EntityType.Backup, backupId);
    }
    return writerForTopLevelObject(request, response, outputWriter -> BackupRepresenter.toJSON(outputWriter, backup.get()));
}
Also used : ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Example 4 with BadRequestException

use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.

the class JobInstanceControllerV1 method getValue.

private Integer getValue(Request request, String paramKey) {
    Integer value;
    String errorMsg = format("The params '%s' must be a number greater than 0.", paramKey);
    try {
        value = Integer.valueOf(request.params(paramKey));
        if (value < 0) {
            throw new BadRequestException(errorMsg);
        }
    } catch (NumberFormatException e) {
        throw new BadRequestException(errorMsg);
    }
    return value;
}
Also used : BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Example 5 with BadRequestException

use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.

the class ExtractTemplateFromPipelineEntityConfigUpdateCommand method canContinue.

@Override
public boolean canContinue(CruiseConfig cruiseConfig) {
    PipelineConfig pipelineConfig = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName));
    if (pipelineConfig == null) {
        throw new RecordNotFoundException(EntityType.Pipeline, pipelineName);
    }
    if (pipelineConfig.hasTemplate()) {
        throw new ConflictException(EntityType.Pipeline.alreadyUsesATemplate(pipelineName));
    }
    PipelineTemplateConfig templateByName = cruiseConfig.getTemplates().templateByName(this.newTemplate.name());
    if (templateByName != null) {
        throw new ConflictException(EntityType.Template.alreadyExists(this.newTemplate.name()));
    }
    if (new NameTypeValidator().isNameInvalid(this.newTemplate.name().toString())) {
        throw new BadRequestException(NameTypeValidator.errorMessage("template", this.newTemplate.name()));
    }
    return true;
}
Also used : NameTypeValidator(com.thoughtworks.go.config.validation.NameTypeValidator) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ConflictException(com.thoughtworks.go.config.exceptions.ConflictException) BadRequestException(com.thoughtworks.go.config.exceptions.BadRequestException)

Aggregations

BadRequestException (com.thoughtworks.go.config.exceptions.BadRequestException)5 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)2 ConflictException (com.thoughtworks.go.config.exceptions.ConflictException)1 NameTypeValidator (com.thoughtworks.go.config.validation.NameTypeValidator)1 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)1 ServerBackup (com.thoughtworks.go.server.domain.ServerBackup)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1