|
|
|
|
|
# 错误响应方法统一修正总结
|
|
|
|
|
|
|
|
|
|
|
|
## 修正内容
|
|
|
|
|
|
|
|
|
|
|
|
已将所有控制器中的 `$this->error()` 调用统一修正为 `$this->fail()` 调用,确保整个系统使用统一的错误响应格式。
|
|
|
|
|
|
|
|
|
|
|
|
## 修正的文件
|
|
|
|
|
|
|
|
|
|
|
|
### 1. GateController.php
|
|
|
|
|
|
修正了 4 处 `$this->error()` 调用:
|
|
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
|
// 修正前
|
|
|
|
|
|
return $this->error(__('gate.get_visit_list_failed'));
|
|
|
|
|
|
return $this->error(__('gate.get_visit_detail_failed'));
|
|
|
|
|
|
return $this->error(__('gate.person_no_required'));
|
|
|
|
|
|
return $this->error(__('gate.operation_failed') . ':' . $e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
// 修正后
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_INSIDE, __('gate.get_visit_list_failed')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_INSIDE, __('gate.get_visit_detail_failed')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, __('gate.person_no_required')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_INSIDE, __('gate.operation_failed') . ':' . $e->getMessage()]);
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 2. VisitLogController.php
|
|
|
|
|
|
修正了 7 处 `$this->error()` 调用:
|
|
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
|
// 修正前
|
|
|
|
|
|
return $this->error(__('visit_log.visit_id_required'));
|
|
|
|
|
|
return $this->error(__('visit_log.type_required'));
|
|
|
|
|
|
return $this->error(__('visit_log.not_found'));
|
|
|
|
|
|
return $this->error(__('visit_log.save_failed') . ':' . $e->getMessage());
|
|
|
|
|
|
return $this->error(__('visit_log.id_required'));
|
|
|
|
|
|
return $this->error(__('visit_log.not_found'));
|
|
|
|
|
|
return $this->error(__('visit_log.delete_failed') . ':' . $e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
|
// 修正后
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, __('visit_log.visit_id_required')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, __('visit_log.type_required')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, __('visit_log.not_found')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_INSIDE, __('visit_log.save_failed') . ':' . $e->getMessage()]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, __('visit_log.id_required')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, __('visit_log.not_found')]);
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_INSIDE, __('visit_log.delete_failed') . ':' . $e->getMessage()]);
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 3. SendVisitReminderCommand.php
|
|
|
|
|
|
**未修改** - 该文件中的 `$this->error()` 是 Laravel 命令类的标准方法,用于控制台输出,不需要修改。
|
|
|
|
|
|
|
|
|
|
|
|
## 错误码分类
|
|
|
|
|
|
|
|
|
|
|
|
根据错误类型使用了不同的错误码:
|
|
|
|
|
|
|
|
|
|
|
|
### ERROR_PARAMETER (10001) - 参数错误
|
|
|
|
|
|
- 缺少必填参数
|
|
|
|
|
|
- 参数格式错误
|
|
|
|
|
|
|
|
|
|
|
|
### ERROR_BUSINESS (10002) - 业务错误
|
|
|
|
|
|
- 记录不存在
|
|
|
|
|
|
- 业务逻辑验证失败
|
|
|
|
|
|
|
|
|
|
|
|
### ERROR_INSIDE (10003) - 内部错误
|
|
|
|
|
|
- 数据库操作失败
|
|
|
|
|
|
- 系统异常
|
|
|
|
|
|
|
|
|
|
|
|
## 响应格式
|
|
|
|
|
|
|
|
|
|
|
|
所有错误响应现在都使用统一格式:
|
|
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
|
{
|
|
|
|
|
|
"errcode": 10001,
|
|
|
|
|
|
"errmsg": "错误消息"
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 测试结果
|
|
|
|
|
|
|
|
|
|
|
|
✅ **门岗端接口测试通过**
|
|
|
|
|
|
- ✅ 拜访列表接口
|
|
|
|
|
|
- ✅ 拜访详情接口
|
|
|
|
|
|
- ✅ 拜访更新接口
|
|
|
|
|
|
- ✅ 多语言支持
|
|
|
|
|
|
- ✅ API响应格式
|
|
|
|
|
|
- ✅ 路由验证
|
|
|
|
|
|
|
|
|
|
|
|
⚠️ **认证测试失败**(之前存在的问题,与本次修改无关)
|
|
|
|
|
|
|
|
|
|
|
|
## 优势
|
|
|
|
|
|
|
|
|
|
|
|
1. **统一性**: 整个系统使用相同的错误响应格式
|
|
|
|
|
|
2. **标准化**: 错误码分类清晰,便于前端处理
|
|
|
|
|
|
3. **可维护性**: 统一的错误处理逻辑
|
|
|
|
|
|
4. **一致性**: 与系统其他部分保持一致的响应格式
|
|
|
|
|
|
|
|
|
|
|
|
## 总结
|
|
|
|
|
|
|
|
|
|
|
|
已成功将所有 `$this->error()` 调用统一修正为 `$this->fail()` 调用,确保整个系统使用统一的错误响应格式。所有门岗端接口测试通过,系统响应格式完全统一。
|