SearchApiResultUtils.java 1.09 KB
package com.yoho.search.common.utils;

import com.yoho.search.base.utils.JsonUtil;
import com.yoho.search.models.SearchApiResult;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class SearchApiResultUtils {

    public static SearchApiResult errorSearchApiResult(final Logger logger,final Object param, final Exception e) {
        logger.error("[※查询]失败:[param={}][message={}][stack={}]", param==null?"":JsonUtil.toJson(param), e.getMessage(), e);
        SearchApiResult searchApiResult = new SearchApiResult();
        searchApiResult.setCode(500);
        searchApiResult.setMessage(e.getMessage());
        searchApiResult.setData(null);
        return searchApiResult;
    }

    public static SearchApiResult defaultErrorSearchApiResult(final Logger logger,final Exception e) {
        logger.error(e.getMessage(),e);
        SearchApiResult searchApiResult = new SearchApiResult();
        searchApiResult.setCode(500);
        searchApiResult.setMessage(e.getMessage());
        searchApiResult.setData(null);
        return searchApiResult;
    }


}