api/app/util/ErrorResponse.php
2019-06-23 22:28:55 +08:00

81 lines
1.6 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: yancheng<cheng@love.xiaoyan.me>
* Date: 2019/6/18
* Time: 4:06 PM
*/
namespace app\util;
use think\Response;
use think\response\Json;
class ErrorCode
{
/**
* 参数不足
*/
const ERROR_PARAM_REQUIRED = 10001;
/**
* 参数错误
*/
const ERROR_PARAM_ERROR = 10002;
/**
* @var 缺失用户openid
*/
const ERROR_OPENID_REQUIRED = 10003;
//用户
/**
* 用户名或密码错误
*/
const ERROR_ADMIN_LOGIN_PWD = 2101;
/**
* 原始密码不正确
*/
const ERROR_ADMIN_PWD_ERROR = 21010;
/**
* 输入的密码不一致
*/
const ERROR_ADMIN_PWD_UN_EQUAL = 21012;
//用户
/**
* 用户不存在
*/
const ERROR_USER_NOT_EXISTS = 22001;
const User_Login_Fail = 22002;
const USER_SAVE_FAIL = 22003;
const USER_EXISTS = 22004;
/**
* 评估
*/
const EVALUATION_SAVE_FAIL = 23005;
const EVALUATION_NOT_EXISTS = 23006;
}
class ErrorResponse extends Json
{
public static function createError($errorCode, $errorMessage = '', $extData = null): Response
{
$ret = [
"code" => $errorCode,
"message" => $errorMessage
];
if ($extData) {
$ret['data'] = $extData;
}
return parent::create($ret); // TODO: Change the autogenerated stub
}
public static function createFromException(\Throwable $e)
{
return parent::create([
'code' => $e->getCode(),
'message' => $e->getMessage()
]);
}
}