/**
 * 封装Restful统一生成函数
 * @author:张金龙
 * @date:2019-1-11
 **/
class Restful {
    APIError(code, message) {
        this.code = code || '500';
        this.message = message || '找不到服务';
    }
    rest(ctx, data) {
        ctx.response.type = 'application/json';
        if (typeof data === 'object' || typeof data === 'undefined') {
            ctx.response.body = {
                Model: data,
                StatusCode: 200,
                Message: "请求(或处理)成功"
            };
        } else {
            switch (data) {
                case '':
                    ctx.response.body = {
                        StatusCode: 408,
                        Message: "未找到相关数据"
                    };
                break;
                default:
                    ctx.response.body = {
                        StatusCode: 409,
                        Message: data || "未知错误"
                    };
                break;
            }
        }
    }

    custom(ctx,{code = 400,Message = ""}){
        ctx.response.body = {
            StatusCode: code,
            Message
        };
    }
}

export default Restful;
