Skip to content

Commit

Permalink
Tests work, improved scribe error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
victoriousgaming committed Nov 17, 2017
1 parent b2e1d2f commit 7369e9c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Laravel/Controllers/RestfulControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace TempestTools\Scribe\Laravel\Controllers;
use ArrayObject;
use Dingo\Api\Exception\ResourceException;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -191,6 +192,9 @@ public function show(Request $request, $id=null): JsonResponse
$this->getConfigArrayHelper()->start();
event(new PreShow($settings));
$result = $repo->read($settings['query'], $settings['frontEndOptions'], $settings['overrides']);
if (count($result['result']) === 0) {
throw new ResourceException('Error: your requested resource does not exist, or you do not have access to it.');
}
$settings['result'] = $result['result'][0];
event(new PostShow($settings));
} catch (Exception $e) {
Expand Down Expand Up @@ -234,6 +238,9 @@ public function update(Request $request, $id=null): JsonResponse
$this->getConfigArrayHelper()->start();
event(new PreUpdate($settings));
$result = $repo->update($settings['params'], $settings['overrides'], $settings['frontEndOptions']);
if ($id !== 'batch' && count($result) === 0) {
throw new ResourceException('Error: the resource you attempted to update does not exist, or you do not have access to it.');
}
$transformerSettings = $this->getTransformerSettings($settings);
$settings['result'] = $this->getTransformer()->setSettings($transformerSettings)->transform($result);
$settings['result'] = $id === 'batch'?$settings['result']:$settings['result'][0];
Expand Down Expand Up @@ -268,6 +275,9 @@ public function destroy(Request $request, $id = null): JsonResponse
event(new PreDestroy($settings));
$result = $repo->delete($settings['params'], $settings['overrides'], $settings['frontEndOptions']);
$transformerSettings = $this->getTransformerSettings($settings);
if ($id !== 'batch' && count($result) === 0) {
throw new ResourceException('Error: the resource you attempted to destroy does not exist, or you do not have access to it.');
}
$settings['result'] = $this->getTransformer()->setSettings($transformerSettings)->transform($result);
$settings['result'] = $id === 'batch'?$settings['result']:$settings['result'][0];
event(new PostDestroy($settings));
Expand Down

0 comments on commit 7369e9c

Please sign in to comment.