Skip to content

Commit 9c2ed2a

Browse files
Log errors during resource update operation (typically these happen a… (#67)
* Log errors during resource update operation (typically these happen at the resource storage layer) * Apply fixes from StyleCI (#68)
1 parent a7c4a2c commit 9c2ed2a

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

helpers/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function APIUser()
1515
*
1616
* @deprecated Use Helpers.php
1717
*
18-
* @param $array
18+
* @param $array
1919
* @param int|null $levels How many levels of an array keys to transform - by default recurse infinitely (null)
2020
* @return array $array
2121
*/
@@ -31,7 +31,7 @@ function camel_case_array_keys($array, $levels = null)
3131
*
3232
* @deprecated Use Helpers.php
3333
*
34-
* @param $array
34+
* @param $array
3535
* @param int|null $levels How many levels of an array keys to transform - by default recurse infinitely (null)
3636
* @return array $array
3737
*/

src/APIHelpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class APIHelpers
99
/**
1010
* Recursively camel-case an array's keys
1111
*
12-
* @param $array
12+
* @param $array
1313
* @param int|null $levels How many levels of an array keys to transform - by default recurse infinitely (null)
1414
* @return array $array
1515
*/
@@ -42,7 +42,7 @@ public static function camelCaseArrayKeys($array, $levels = null)
4242
/**
4343
* Recursively snake-case an array's keys
4444
*
45-
* @param $array
45+
* @param $array
4646
* @param int|null $levels How many levels of an array keys to transform - by default recurse infinitely (null)
4747
* @return array $array
4848
*/

src/Http/Controllers/Features/RestfulControllerTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function shouldTransform()
107107
* Useful for adding error info to internal request responses before returning them
108108
*
109109
* @param \Dingo\Api\Http\Response $response
110-
* @param $message
110+
* @param $message
111111
* @return \Dingo\Api\Http\Response
112112
*/
113113
protected function prependResponseMessage($response, $message)
@@ -122,8 +122,8 @@ protected function prependResponseMessage($response, $message)
122122
/**
123123
* Try to find the relation name of the child model in the parent model
124124
*
125-
* @param $parent Object Parent model instance
126-
* @param $child string Child model name
125+
* @param $parent Object Parent model instance
126+
* @param $child string Child model name
127127
* @return null|string
128128
*/
129129
protected function getChildRelationNameForParent($parent, $child)

src/Http/Controllers/RestfulChildController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class RestfulChildController extends BaseRestfulController
3030
* @var array
3131
*/
3232
public $parentAbilitiesRequired = [
33-
'create' => 'update',
34-
'view' => 'view',
35-
'viewAll' => 'view',
36-
'update' => 'own',
37-
'delete' => 'own',
33+
'create' => 'update',
34+
'view' => 'view',
35+
'viewAll' => 'view',
36+
'update' => 'own',
37+
'delete' => 'own',
3838
];
3939

4040
/**

src/Services/RestfulService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Http\Request;
88
use Illuminate\Support\Str;
99
use Illuminate\Database\QueryException;
10+
use Illuminate\Support\Facades\Log;
1011
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1112
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
1213
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
@@ -51,8 +52,8 @@ public function setModel($model)
5152
/**
5253
* Deletes resources of the given model and uuid(s)
5354
*
54-
* @param $model string Model class name
55-
* @param $uuid string|array The UUID(s) of the models to remove
55+
* @param $model string Model class name
56+
* @param $uuid string|array The UUID(s) of the models to remove
5657
* @return mixed
5758
*/
5859
public function delete($model, $uuid)
@@ -82,6 +83,9 @@ public function patch($model, array $data)
8283
try {
8384
$resource = $model->update($data);
8485
} catch (\Exception $e) {
86+
// Log this as an unexpected exception, useful if API debug is off
87+
Log::error('Error updating resource ' . get_class($model) . ': ' . $e->getMessage());
88+
8589
// Check for QueryException - if so, we may want to display a more meaningful message, or help with
8690
// development debugging
8791
if ($e instanceof QueryException) {
@@ -108,15 +112,18 @@ public function patch($model, array $data)
108112
/**
109113
* Create model in the database
110114
*
111-
* @param $model
112-
* @param $data
115+
* @param $model
116+
* @param $data
113117
* @return mixed
114118
*/
115119
public function persistResource(RestfulModel $resource)
116120
{
117121
try {
118122
$resource->save();
119123
} catch (\Exception $e) {
124+
// Log this as an unexpected exception, useful if API debug is off
125+
Log::error('Error persisting resource ' . get_class($resource) . ': ' . $e->getMessage());
126+
120127
// Check for QueryException - if so, we may want to display a more meaningful message, or help with
121128
// development debugging
122129
if ($e instanceof QueryException) {

0 commit comments

Comments
 (0)