Skip to content

Commit

Permalink
Fix exception handling for DL routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlpp committed Oct 12, 2023
1 parent f1fdd74 commit cb576b8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/form/src/components/fields/upload/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
</template>
<template v-if="value?.path">
<a class="text-sm text-primary-700 underline"
:href="route('code16.sharp.api.download.show', {
:href="route('code16.sharp.download.show', {
entityKey: form.entityKey,
instanceId: form.instanceId,
disk: value.disk,
Expand Down
2 changes: 0 additions & 2 deletions src/Exceptions/Auth/SharpAuthorizationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Code16\Sharp\Exceptions\Auth;

use Code16\Sharp\Exceptions\SharpException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class SharpAuthorizationException extends SharpException
{
Expand Down
5 changes: 0 additions & 5 deletions src/Http/Middleware/Api/HandleSharpApiErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
namespace Code16\Sharp\Http\Middleware\Api;

use Closure;
use Code16\Sharp\Exceptions\Auth\SharpAuthorizationException;
use Code16\Sharp\Exceptions\EntityList\SharpInvalidEntityStateException;
use Code16\Sharp\Exceptions\Form\SharpApplicativeException;
use Code16\Sharp\Exceptions\Form\SharpFormFieldValidationException;
use Code16\Sharp\Exceptions\SharpException;
use Code16\Sharp\Exceptions\SharpInvalidEntityKeyException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Middleware/HandleSharpErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;

class HandleSharpErrors
{
public function handle(Request $request, Closure $next)
{
/**
* @var \Illuminate\Http\Response $response
*/
$response = $next($request);

if($response->exception instanceof ValidationException) {
Expand All @@ -26,6 +24,7 @@ public function handle(Request $request, Closure $next)
new SharpException(
$response->exception->getMessage(),
match(true) {
$response->exception instanceof HttpException => $response->getStatusCode(),
$response->exception instanceof ModelNotFoundException => 404,
default => 500
},
Expand Down
6 changes: 3 additions & 3 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
Route::get('/search', [ApiSearchController::class, 'index'])
->name('code16.sharp.api.search.index');

Route::get('/download/{entityKey}/{instanceId?}', [DownloadController::class, 'show'])
->name('code16.sharp.api.download.show');

Route::post('/files/{entityKey}/{instanceId?}', [ApiFilesController::class, 'show'])
->name('code16.sharp.api.files.show');

Expand Down Expand Up @@ -134,6 +131,9 @@
Route::get('/s-show/{entityKey}', [SingleShowController::class, 'show'])
->name('code16.sharp.single-show');

Route::get('/download/{entityKey}/{instanceId?}', [DownloadController::class, 'show'])
->name('code16.sharp.download.show');

Route::group([
'prefix' => '/{uri}',
'where' => ['uri' => '(s-list|s-show)/.*'],
Expand Down
8 changes: 4 additions & 4 deletions tests/Http/Api/DownloadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

$response = $this
->get(
route('code16.sharp.api.download.show', [
route('code16.sharp.download.show', [
'entityKey' => 'person',
'instanceId' => 1,
'disk' => 'local',
Expand All @@ -41,7 +41,7 @@

$response = $this
->get(
route('code16.sharp.api.download.show', [
route('code16.sharp.download.show', [
'entityKey' => 'person',
'instanceId' => 1,
'disk' => 'local',
Expand All @@ -61,7 +61,7 @@
url('/sharp/s-list/person/s-form/person/1'),
)
->get(
route('code16.sharp.api.download.show', [
route('code16.sharp.download.show', [
'entityKey' => 'person',
'instanceId' => 1,
'fileName' => 'test.jpg',
Expand All @@ -77,7 +77,7 @@

$this
->get(
route('code16.sharp.api.download.show', [
route('code16.sharp.download.show', [
'entityKey' => 'person',
'instanceId' => 1,
'disk' => 'local',
Expand Down

0 comments on commit cb576b8

Please sign in to comment.