All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.maha.parrequest2.GeneralError Maven / Gradle / Ivy

There is a newer version: 6.158
Show newest version
// Copyright 2017, Yahoo Holdings Inc.
// Licensed under the terms of the Apache License 2.0. Please see LICENSE file in project root for terms.
package com.yahoo.maha.parrequest2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.Option;
import scala.util.Either;
import scala.util.Left;

/**
 * hiral, srikalyan
 */
public class GeneralError {

    private static Logger logger = LoggerFactory.getLogger(GeneralError.class);
    public final String stage;
    public final String message;
    public final Option throwableOption;

    public GeneralError(String stage, String message, Option throwableOption) {
        this.stage = stage;
        this.message = message;
        this.throwableOption = throwableOption;
        logger.debug("Stage {}, Message {}", stage, message);
        logger.debug("StackTrace {}", throwableOption);
    }

    GeneralError prependStage(String s) {
        return new GeneralError(String.format("%s :: %s", s, this.stage), this.message, this.throwableOption);
    }

    @Override
    public String toString() {
        return "GeneralError{" +
               "stage='" + stage + '\'' +
               ", message='" + message + '\'' +
               ", throwableOption=" + throwableOption +
               '}';
    }

    public static GeneralError from(String stage, String message) {
        return new GeneralError(stage, message, Option.empty());
    }

    public static GeneralError from(String stage, String message, Throwable t) {
        return new GeneralError(stage, message, Option.apply(t));
    }

    public static  Either either(String stage, String message) {
        return new Left(from(stage, message));
    }

    public static  Either either(String stage, String message, Throwable t) {
        return new Left(from(stage, message, t));
    }

    static  Either prependStage(Either either, final String s) {
                return new Left(either.left().get().prependStage(s));
    }

    static  Either prependStageAndCastLeft(Either either,
                                                                         final String s) {
        return new Left(either.left().get().prependStage(s));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy