refactor: 使用 ApiMessage 统一错误响应格式
- 在多个控制器中引入 ApiMessage,替换原有的 ApiResponse 错误处理逻辑,确保错误信息的一致性与可读性。 - 更新错误返回信息,使用更具语义的键值,提升 API 的可维护性与用户体验。 - 适配相关控制器的请求参数,确保在处理错误时能够正确返回相应的错误信息。
This commit is contained in:
@@ -329,10 +329,11 @@ test('admin cannot delete self', function (): void {
|
||||
$me = AdminUser::query()->where('username', 'self_guard')->firstOrFail();
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer '.$token)
|
||||
->withHeader('X-Locale', 'zh')
|
||||
->deleteJson('/api/v1/admin/admin-users/'.$me->id)
|
||||
->assertStatus(422)
|
||||
->assertJsonPath('code', ErrorCode::ValidationFailed->value)
|
||||
->assertJsonPath('msg', '不能删除当前登录账号');
|
||||
->assertJsonPath('msg', '不能删除当前登录账号。');
|
||||
});
|
||||
|
||||
test('admin cannot delete the last super admin', function (): void {
|
||||
@@ -348,9 +349,10 @@ test('admin cannot delete the last super admin', function (): void {
|
||||
grantSuperAdminRole($s1);
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer '.$token)
|
||||
->withHeader('X-Locale', 'zh')
|
||||
->deleteJson('/api/v1/admin/admin-users/'.$s1->id)
|
||||
->assertStatus(422)
|
||||
->assertJsonPath('msg', '不能删除最后一个超级管理员');
|
||||
->assertJsonPath('msg', '不能删除最后一个超级管理员。');
|
||||
|
||||
$s2 = AdminUser::query()->create([
|
||||
'username' => 'super_two',
|
||||
@@ -362,11 +364,13 @@ test('admin cannot delete the last super admin', function (): void {
|
||||
grantSuperAdminRole($s2);
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer '.$token)
|
||||
->withHeader('X-Locale', 'zh')
|
||||
->deleteJson('/api/v1/admin/admin-users/'.$s1->id)
|
||||
->assertOk();
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer '.$token)
|
||||
->withHeader('X-Locale', 'zh')
|
||||
->deleteJson('/api/v1/admin/admin-users/'.$s2->id)
|
||||
->assertStatus(422)
|
||||
->assertJsonPath('msg', '不能删除最后一个超级管理员');
|
||||
->assertJsonPath('msg', '不能删除最后一个超级管理员。');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user