@Test public void whenEmpty() { assertThat(composite.recognize(new RuntimeException()), is(nullValue())); }
/** * Returns the non-<tt>null</tt> recognition of the first {@link #add(ExceptionRecognizer) add}ed * (that is also an {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2}). * * <p> * If none (as {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2}) recognize * the exception, then falls back to using {@link #recognize(Throwable)}, returning a * {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2.Recognition} with a * category of {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2.Category#CLIENT_ERROR}. * </p> */ @Programmatic public final Recognition recognize2(final Throwable ex) { for (final ExceptionRecognizer ers : exceptionRecognizers) { if(ers instanceof ExceptionRecognizer2) { final ExceptionRecognizer2 recognizer2 = (ExceptionRecognizer2) ers; final Recognition recognition = recognizer2.recognize2(ex); if(recognition != null) { return recognition; } } } // backward compatible so far as possible. return Recognition.of(Category.OTHER, recognize(ex)); }
protected IRequestablePage errorPageFor(Exception ex) { List<ExceptionRecognizer> exceptionRecognizers = Lists.newArrayList(); exceptionRecognizers.add(pageExpiredExceptionRecognizer); if(inIsisSession()) { exceptionRecognizers.addAll(getServicesInjector().lookupServices(ExceptionRecognizer.class)); } else { final MetaModelInvalidException mmie = IsisContext.getMetaModelInvalidExceptionIfAny(); if(mmie != null) { Set<String> validationErrors = mmie.getValidationErrors(); return new MmvErrorPage(validationErrors); } // not sure whether this can ever happen now... LOG.warn("Unable to obtain exceptionRecognizers (no session), will be treated as unrecognized exception", ex); } String recognizedMessageIfAny = new ExceptionRecognizerComposite(exceptionRecognizers).recognize(ex); ExceptionModel exceptionModel = ExceptionModel.create(recognizedMessageIfAny, ex); return isSignedIn() ? new ErrorPage(exceptionModel) : newSignInPage(exceptionModel); }
@Test public void whenOne() { composite.add(new FakeERS("one")); assertThat(composite.recognize(new RuntimeException()), is("one")); }
@Test public void whenOneThenTwo() { composite.add(new FakeERS("one")); composite.add(new FakeERS("two")); assertThat(composite.recognize(new RuntimeException()), is("one")); } }
@Test public void whenNullThenOne() { composite.add(new FakeERS(null)); composite.add(new FakeERS("one")); assertThat(composite.recognize(new RuntimeException()), is("one")); }