Search in sources :

Example 21 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class PostSubscriptionControllerTest method whenCreateSubscriptionWithEmptyOwningApplicationThenUnprocessableEntity.

@Test
public void whenCreateSubscriptionWithEmptyOwningApplicationThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().withOwningApplication("").buildSubscriptionBase();
    final Problem expectedProblem = invalidProblem("owning_application", "must contain at least one character");
    checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 22 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class CursorsControllerTest method whenInvalidCursorExceptionThenUnprocessableEntity.

@Test
public void whenInvalidCursorExceptionThenUnprocessableEntity() throws Exception {
    when(cursorsService.commitCursors(any(), any(), any())).thenThrow((new InvalidCursorException(CursorError.NULL_PARTITION, new SubscriptionCursor(null, null, null, null))));
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "partition must not be null");
    checkForProblem(postCursors(DUMMY_CURSORS), expectedProblem);
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 23 with Problem

use of org.zalando.problem.Problem in project cetc by DiscoverForever.

the class ExceptionTranslator method handleMethodArgumentNotValid.

@Override
public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, @Nonnull NativeWebRequest request) {
    BindingResult result = ex.getBindingResult();
    List<FieldErrorVM> fieldErrors = result.getFieldErrors().stream().map(f -> new FieldErrorVM(f.getObjectName(), f.getField(), f.getCode())).collect(Collectors.toList());
    Problem problem = Problem.builder().withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE).withTitle("Method argument not valid").withStatus(defaultConstraintViolationStatus()).with("message", ErrorConstants.ERR_VALIDATION).with("fieldErrors", fieldErrors).build();
    return create(ex, problem, request);
}
Also used : ControllerAdvice(org.springframework.web.bind.annotation.ControllerAdvice) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) BindingResult(org.springframework.validation.BindingResult) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ProblemHandling(org.zalando.problem.spring.web.advice.ProblemHandling) Collectors(java.util.stream.Collectors) DefaultProblem(org.zalando.problem.DefaultProblem) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Problem(org.zalando.problem.Problem) ProblemBuilder(org.zalando.problem.ProblemBuilder) Status(org.zalando.problem.Status) ConstraintViolationProblem(org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) HeaderUtil(com.cetc.cctv.web.rest.util.HeaderUtil) ResponseEntity(org.springframework.http.ResponseEntity) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BindingResult(org.springframework.validation.BindingResult) DefaultProblem(org.zalando.problem.DefaultProblem) Problem(org.zalando.problem.Problem) ConstraintViolationProblem(org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem)

Example 24 with Problem

use of org.zalando.problem.Problem in project nakadi by zalando.

the class SubscriptionService method listSubscriptions.

public Result listSubscriptions(@Nullable final String owningApplication, @Nullable final Set<String> eventTypes, final int limit, final int offset) {
    if (limit < 1 || limit > 1000) {
        final Problem problem = Problem.valueOf(Response.Status.BAD_REQUEST, "'limit' parameter should have value from 1 to 1000");
        return Result.problem(problem);
    }
    if (offset < 0) {
        final Problem problem = Problem.valueOf(Response.Status.BAD_REQUEST, "'offset' parameter can't be lower than 0");
        return Result.problem(problem);
    }
    try {
        final Set<String> eventTypesFilter = eventTypes == null ? ImmutableSet.of() : eventTypes;
        final Optional<String> owningAppOption = Optional.ofNullable(owningApplication);
        final List<Subscription> subscriptions = subscriptionRepository.listSubscriptions(eventTypesFilter, owningAppOption, offset, limit);
        final PaginationLinks paginationLinks = SubscriptionsUriHelper.createSubscriptionPaginationLinks(owningAppOption, eventTypesFilter, offset, limit, subscriptions.size());
        return Result.ok(new PaginationWrapper<>(subscriptions, paginationLinks));
    } catch (final ServiceUnavailableException e) {
        LOG.error("Error occurred during listing of subscriptions", e);
        return Result.problem(e.asProblem());
    }
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) Problem(org.zalando.problem.Problem) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) Subscription(org.zalando.nakadi.domain.Subscription)

Example 25 with Problem

use of org.zalando.problem.Problem in project FuryViewer by TheDoctor-95.

the class ExceptionTranslator method handleMethodArgumentNotValid.

@Override
public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, @Nonnull NativeWebRequest request) {
    BindingResult result = ex.getBindingResult();
    List<FieldErrorVM> fieldErrors = result.getFieldErrors().stream().map(f -> new FieldErrorVM(f.getObjectName(), f.getField(), f.getCode())).collect(Collectors.toList());
    Problem problem = Problem.builder().withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE).withTitle("Method argument not valid").withStatus(defaultConstraintViolationStatus()).with("message", ErrorConstants.ERR_VALIDATION).with("fieldErrors", fieldErrors).build();
    return create(ex, problem, request);
}
Also used : ControllerAdvice(org.springframework.web.bind.annotation.ControllerAdvice) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) BindingResult(org.springframework.validation.BindingResult) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ProblemHandling(org.zalando.problem.spring.web.advice.ProblemHandling) Collectors(java.util.stream.Collectors) DefaultProblem(org.zalando.problem.DefaultProblem) HeaderUtil(com.furyviewer.web.rest.util.HeaderUtil) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Problem(org.zalando.problem.Problem) ProblemBuilder(org.zalando.problem.ProblemBuilder) Status(org.zalando.problem.Status) ConstraintViolationProblem(org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseEntity(org.springframework.http.ResponseEntity) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BindingResult(org.springframework.validation.BindingResult) DefaultProblem(org.zalando.problem.DefaultProblem) Problem(org.zalando.problem.Problem) ConstraintViolationProblem(org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem)

Aggregations

Problem (org.zalando.problem.Problem)75 Test (org.junit.Test)47 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)32 ResponseEntity (org.springframework.http.ResponseEntity)26 DefaultProblem (org.zalando.problem.DefaultProblem)26 ProblemBuilder (org.zalando.problem.ProblemBuilder)26 ConstraintViolationProblem (org.zalando.problem.spring.web.advice.validation.ConstraintViolationProblem)26 ThrowableProblem (org.zalando.problem.ThrowableProblem)25 EventType (org.zalando.nakadi.domain.EventType)18 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)18 NativeWebRequest (org.springframework.web.context.request.NativeWebRequest)14 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 Nonnull (javax.annotation.Nonnull)13 Nullable (javax.annotation.Nullable)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 BindingResult (org.springframework.validation.BindingResult)13 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)13 ControllerAdvice (org.springframework.web.bind.annotation.ControllerAdvice)13 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)13