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);
}
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);
}
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);
}
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());
}
}
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);
}
Aggregations