diff --git a/resources/js/components/assets/Upload.vue b/resources/js/components/assets/Upload.vue
index 5e36e0d159..8fb5b5a3b7 100644
--- a/resources/js/components/assets/Upload.vue
+++ b/resources/js/components/assets/Upload.vue
@@ -21,7 +21,7 @@
{{ error }}
-
+
diff --git a/resources/js/components/assets/Uploader.vue b/resources/js/components/assets/Uploader.vue
index ea8536ed5c..7a5439e12d 100644
--- a/resources/js/components/assets/Uploader.vue
+++ b/resources/js/components/assets/Uploader.vue
@@ -213,7 +213,7 @@ export default {
msg = __('Upload failed. The file might be larger than is allowed by your server.');
}
} else {
- if (status === 422) {
+ if ([422, 409].includes(status)) {
msg = Object.values(response.errors)[0][0]; // Get first validation message.
}
}
diff --git a/src/Http/Controllers/CP/Assets/AssetsController.php b/src/Http/Controllers/CP/Assets/AssetsController.php
index d755a5cc7f..2fb941d661 100644
--- a/src/Http/Controllers/CP/Assets/AssetsController.php
+++ b/src/Http/Controllers/CP/Assets/AssetsController.php
@@ -4,6 +4,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
+use Illuminate\Validation\ValidationException;
use Statamic\Assets\AssetUploader;
use Statamic\Assets\UploadedReplacementFile;
use Statamic\Contracts\Assets\Asset as AssetContract;
@@ -97,7 +98,11 @@ public function store(Request $request)
$validator = Validator::make(['path' => $path], ['path' => new UploadableAssetPath($container)]);
if (! in_array($request->option, ['timestamp', 'overwrite'])) {
- $validator->validate();
+ try {
+ $validator->validate();
+ } catch (ValidationException $e) {
+ throw $e->status(409);
+ }
}
$asset = $container->asset($path) ?? $container->makeAsset($path);
diff --git a/tests/Feature/Assets/StoreAssetTest.php b/tests/Feature/Assets/StoreAssetTest.php
index a48dac5079..392988fa7a 100644
--- a/tests/Feature/Assets/StoreAssetTest.php
+++ b/tests/Feature/Assets/StoreAssetTest.php
@@ -115,7 +115,7 @@ public function it_doesnt_upload_when_file_exists()
$this
->actingAs($this->userWithPermission())
->submit()
- ->assertStatus(422)
+ ->assertStatus(409)
->assertInvalid(['path' => 'A file already exists with this name.']);
}
@@ -130,7 +130,7 @@ public function it_doesnt_upload_when_file_exists_with_different_casing()
->submit([
'file' => UploadedFile::fake()->image('tEsT.jpg'),
])
- ->assertStatus(422)
+ ->assertStatus(409)
->assertInvalid(['path' => 'A file already exists with this name.']);
}