package cn.fateverse.common.security.utils;

import cn.fateverse.common.core.result.Result;
import com.alibaba.fastjson2.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Clay
 * @date 2024/4/19 9:09
 */
public class ResponseRender {
    /**
     * 将字符串渲染到客户端
     *
     * @param response 渲染对象
     * @param result   返回的错误对象
     */
    public static void renderString(HttpServletResponse response, Result<Object> result) {
        try {
            response.setStatus(result.getStatus().value());
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(JSON.toJSONString(result));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
