Skip to content

Commit 0e13961

Browse files
anas-srikoudaniilly
authored andcommitted
DP-553 Add logging to catch exception and write them to file
1 parent c70512e commit 0e13961

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

src/Database/Schema/TableSchema.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DreamFactory\Core\Database\Schema;
44

55
use DreamFactory\Core\Enums\DbSimpleTypes;
6+
use Illuminate\Support\Facades\Log;
67

78

89
/**
@@ -203,20 +204,28 @@ public function getColumnNames($use_alias = false)
203204
*
204205
* @return ColumnSchema[]
205206
*/
206-
public function getColumns($use_alias = false)
207+
public function getColumns(bool $use_alias = false): array
207208
{
208-
if ($use_alias) {
209-
// re-index for alias usage, easier to find requested fields from client
210-
$columns = [];
211-
/** @var ColumnSchema $column */
209+
if (!$use_alias) {
210+
return !is_array($this->columns) ? [] : $this->columns;
211+
}
212+
213+
// re-index for alias usage, easier to find requested fields from client
214+
$columns = [];
215+
$this->columns = null;
216+
217+
/** @var ColumnSchema $column */
218+
try {
212219
foreach ($this->columns as $column) {
213220
$columns[strtolower($column->getName(true))] = $column;
214221
}
215-
216-
return $columns;
222+
} catch (\Exception $exception) {
223+
Log::info("Columns field type: " . gettype($this->columns));
224+
Log::error($exception->getMessage());
225+
Log::error($exception->getTraceAsString());
217226
}
218227

219-
return $this->columns;
228+
return $columns;
220229
}
221230

222231
public function addRelation(RelationSchema $relation)
@@ -301,9 +310,16 @@ public function toArray($use_alias = false)
301310

302311
$fields = [];
303312
/** @var ColumnSchema $column */
304-
foreach ($this->columns as $column) {
305-
$fields[] = $column->toArray($use_alias);
313+
try {
314+
foreach ($this->columns as $column) {
315+
$fields[] = $column->toArray($use_alias);
316+
}
317+
} catch (\Exception $exception) {
318+
Log::info("Columns field type: " . gettype($this->columns));
319+
Log::error($exception->getMessage());
320+
Log::error($exception->getTraceAsString());
306321
}
322+
307323
$out['field'] = $fields;
308324

309325
$relations = [];

0 commit comments

Comments
 (0)