Source:
<code>public void listChannels(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = TYPE_KEY, required = false) String type, @RequestParam(value = PLATFORM_ID_KEY, required = false) String platformId, @RequestParam(value = ADVERTISED, required = false) String advertised) throws IOException { try { final ApplicationConfiguration appConfig; try { appConfig = appConfig(request); } catch (ApiKeyNotFoundException | RevokedApiKeyException | InvalidIpForApiKeyException ex) { <START> outputter.writeError(request, response, FORBIDDEN); <END> return; } Optional<Set<Annotation>> annotations = annotationExtractor.extract(request); if (annotations.isPresent() && !validAnnotations(annotations.get())) { errorViewFor(request, response, BAD_ANNOTATION); return; } List<ChannelGroup> channelGroups = ImmutableList.copyOf(channelGroupResolver.channelGroups()); Selection selection = SELECTION_BUILDER.build(request); channelGroups = selection.applyTo(Iterables.filter( filterer.filter(channelGroups, constructFilter(platformId, type, advertised)), new Predicate<ChannelGroup>() { @Override public boolean apply(ChannelGroup input) { return appConfig.isEnabled(input.getPublisher()); } })); if (!Strings.isNullOrEmpty(advertised)) { ImmutableList.Builder filtered = ImmutableList.builder(); for (ChannelGroup channelGroup : channelGroups) { filtered.add(filterByAdvertised(channelGroup)); } channelGroups = filtered.build(); } modelAndViewFor(request, response, channelGroups, appConfig); } catch (Exception e) { errorViewFor(request, response, AtlasErrorSummary.forException(e)); } }</code><technical_language>This current pattern. reuse errorViewFor pattern add exceptions AtlasErrorSummary class</technical_language>

Target:
public void listChannels(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = TYPE_KEY, required = false) String type, @RequestParam(value = PLATFORM_ID_KEY, required = false) String platformId, @RequestParam(value = ADVERTISED, required = false) String advertised) throws IOException { try { final ApplicationConfiguration appConfig; try { appConfig = appConfig(request); } catch (ApiKeyNotFoundException | RevokedApiKeyException | InvalidIpForApiKeyException ex) { errorViewFor(request, response, AtlasErrorSummary.forException(ex)); return; } Optional<Set<Annotation>> annotations = annotationExtractor.extract(request); if (annotations.isPresent() && !validAnnotations(annotations.get())) { errorViewFor(request, response, BAD_ANNOTATION); return; } List<ChannelGroup> channelGroups = ImmutableList.copyOf(channelGroupResolver.channelGroups()); Selection selection = SELECTION_BUILDER.build(request); channelGroups = selection.applyTo(Iterables.filter( filterer.filter(channelGroups, constructFilter(platformId, type, advertised)), new Predicate<ChannelGroup>() { @Override public boolean apply(ChannelGroup input) { return appConfig.isEnabled(input.getPublisher()); } })); if (!Strings.isNullOrEmpty(advertised)) { ImmutableList.Builder filtered = ImmutableList.builder(); for (ChannelGroup channelGroup : channelGroups) { filtered.add(filterByAdvertised(channelGroup)); } channelGroups = filtered.build(); } modelAndViewFor(request, response, channelGroups, appConfig); } catch (Exception e) { errorViewFor(request, response, AtlasErrorSummary.forException(e)); } }