001/*******************************************************************************
002 * Copyright (c) 2017 Red Hat Inc and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Red Hat Inc - initial API and implementation
011 *******************************************************************************/
012package org.eclipse.kapua.gateway.client;
013
014import java.util.Optional;
015import java.util.function.BiConsumer;
016
017public final class Errors {
018
019    private static final ErrorHandler<RuntimeException> IGNORE = Errors::ignore;
020
021    private Errors() {
022    }
023
024    public static ErrorHandler<RuntimeException> ignore() {
025        return IGNORE;
026    }
027
028    public static ErrorHandler<RuntimeException> handle(BiConsumer<Throwable, Optional<Payload>> handler) {
029        return new ErrorHandler<RuntimeException>() {
030
031            @Override
032            public void handleError(Throwable e, Optional<Payload> payload) throws RuntimeException {
033                handler.accept(e, payload);
034            }
035        };
036    }
037
038    public static void ignore(final Throwable e, final Optional<Payload> payload) {
039    }
040}