package com.youchain.utils;

import com.youchain.businessdata.inputJson.IRkStockCode;
import com.youchain.exception.handler.ApiError;
import com.youchain.exception.handler.ApiResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import static org.springframework.http.HttpStatus.BAD_REQUEST;

public class HttpUtils {
    public static ResponseEntity<Object> handle(ApiResult r){
        if(r.getStatus()==400){
            ApiError apiError = ApiError.errorJosn(BAD_REQUEST.value(),r.getMessage());
            return new ResponseEntity(apiError, HttpStatus.valueOf(apiError.getStatus()));
        }else{
            return new ResponseEntity<>(r.getData(),HttpStatus.OK);
        }
    }
}
