public function sendErrorResponse($message, $code, $httpStatusCode, $data = null)
    {

        \Yii::$app->response->format = Response::FORMAT_JSON;
        \Yii::$app->response->setStatusCode($httpStatusCode, $this->httpStatuses->getReasonPhrase($httpStatusCode));

        $response = [
            'status' => 'error',
            'message' => $message,
            'code' => $code
        ];

        if (!is_null($data)) {
            $response["data"] = $data;
        }

        return $response;
    }
public function sendErrorResponse($message, $code, $httpStatusCode, $data = null)
    {

        \Yii::$app->response->format = Response::FORMAT_JSON;
        \Yii::$app->response->setStatusCode($httpStatusCode, $this->httpStatuses->getReasonPhrase($httpStatusCode));

        $response = [
            'status' => 'error',
            'message' => $message,
            'code' => $code
        ];

        if (!is_null($data)) {
            $response["data"] = $data;
        }

        return $response;
    }
public function sendErrorResponse ( $ message , $ code , $ httpStatusCode , $ data = null ) { \ Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; \ Yii :: $ app -> response -> setStatusCode ( $ httpStatusCode , $ this -> httpStatuses -> getReasonPhrase ( $ httpStatusCode ) ) ; $ response = [ 'status' => 'error' , 'message' => $ message , 'code' => $ code ] ; if ( ! is_null ( $ data ) ) { $ response [ "data" ] = $ data ; } return $ response ; }
Allows sending error response
@author Oluwarotimi Akintewe <akintewe.rotimi@gmail.com>
@author Adegoke Obasa <goke@cottacush.com>
@param $message
@param $code
@param $httpStatusCode
@param null $data
@return array
Allows sending error response