package com.common.lib_base.common.http.exception;

import android.content.Context;

import com.common.lib_base.R;


/**
 * Created by admin on 2018/3/16.
 *
 * @version $Rev$
 * @time 2018/3/16 11:30
 * @des ${TODO}
 * @updateAuthor $Author$
 * @updateDate $Date$
 * @updateDes ${TODO}
 */

public class ErrorMessageFactory {

    public static String create(Context context, String code){




        String errorMsg = null ;


        switch (code){

            case BaseException.HTTP_ERROR:

                errorMsg =  context.getResources().getString(R.string.error_http);

                break;

            case BaseException.SOCKET_TIMEOUT_ERROR:

                errorMsg =  context.getResources().getString(R.string.error_socket_timeout);

                break;
            case BaseException.SOCKET_ERROR:

                errorMsg =  context.getResources().getString(R.string.error_socket_unreachable);

                break;


            case BaseException.ERROR_HTTP_400:

                errorMsg =  context.getResources().getString(R.string.error_http_400);

                break;


            case BaseException.ERROR_HTTP_404:

                errorMsg =  context.getResources().getString(R.string.error_http_404);

                break;

            case BaseException.ERROR_HTTP_500:

                errorMsg =  context.getResources().getString(R.string.error_http_500);

                break;



            case ApiException.ERROR_API_SYSTEM:
                errorMsg = context.getResources().getString(R.string.error_system);
                break;

            case ApiException.ERROR_API_ACCOUNT_FREEZE:
                errorMsg = context.getResources().getString(R.string.error_account_freeze);
                break;


            case ApiException.ERROR_API_NO_PERMISSION:
                errorMsg = context.getResources().getString(R.string.error_api_no_perission);
                break;

//            case ApiException.ERROR_API_LOGIN:
//                errorMsg = context.getResources().getString(R.string.error_login);
//                break;

            case ApiException.ERROR_TOKEN:
                errorMsg = context.getResources().getString(R.string.error_token);
                break;

            case ApiException.JSON_ERROR:
                // 若json解析错误，可用charles转本地文件，修改文件中的字段来验证
                errorMsg = context.getResources().getString(R.string.error_json);
                break;

            default:
                errorMsg=context.getResources().getString(R.string.error_unkown);
                break;


        }


        return  errorMsg;


    }

}
