Add an InternalError type that piggybacks ValidationError
This commit is contained in:
32
app/Exceptions/InternalError.php
Normal file
32
app/Exceptions/InternalError.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Validator;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show an internal error, bug piggyback off of the validation
|
||||||
|
* exception type - this has a place to show up in the UI as a
|
||||||
|
* flash message.
|
||||||
|
* @package App\Exceptions
|
||||||
|
*/
|
||||||
|
class InternalError extends ValidationException
|
||||||
|
{
|
||||||
|
protected const FLASH_FIELD_NAME = 'internal_error_message';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InternalError constructor.
|
||||||
|
* @param string|null $message
|
||||||
|
* @param null $field
|
||||||
|
*/
|
||||||
|
final public function __construct(string $message = null, $field = null)
|
||||||
|
{
|
||||||
|
Log::error($message);
|
||||||
|
$validator = Validator::make([], []);
|
||||||
|
$validator->errors()->add($field ?? static::FLASH_FIELD_NAME, $message);
|
||||||
|
|
||||||
|
parent::__construct($validator);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,8 @@ class ImportService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Throw a validation error back up because it will automatically show
|
||||||
|
* itself under the CSV file upload, and nothing special needs to be done
|
||||||
* @param $error
|
* @param $error
|
||||||
* @param $e
|
* @param $e
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
@@ -72,13 +74,15 @@ class ImportService extends Service
|
|||||||
/**
|
/**
|
||||||
* Run the actual importer, pass in one of the Import classes which implements
|
* Run the actual importer, pass in one of the Import classes which implements
|
||||||
* the ImportExport interface
|
* the ImportExport interface
|
||||||
* @param Reader $reader
|
* @param $file_path
|
||||||
* @param ImportExport $importer
|
* @param ImportExport $importer
|
||||||
* @return array
|
* @return array
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
protected function runImport(Reader $reader, ImportExport $importer): array
|
protected function runImport($file_path, ImportExport $importer): array
|
||||||
{
|
{
|
||||||
|
$reader = $this->openCsv($file_path);
|
||||||
|
|
||||||
$cols = $importer->getColumns();
|
$cols = $importer->getColumns();
|
||||||
$first_header = $cols[0];
|
$first_header = $cols[0];
|
||||||
|
|
||||||
@@ -126,13 +130,8 @@ class ImportService extends Service
|
|||||||
# TODO: delete airports
|
# TODO: delete airports
|
||||||
}
|
}
|
||||||
|
|
||||||
$reader = $this->openCsv($csv_file);
|
|
||||||
if (!$reader) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$importer = new AircraftImporter();
|
$importer = new AircraftImporter();
|
||||||
return $this->runImport($reader, $importer);
|
return $this->runImport($csv_file, $importer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -148,13 +147,8 @@ class ImportService extends Service
|
|||||||
Airport::truncate();
|
Airport::truncate();
|
||||||
}
|
}
|
||||||
|
|
||||||
$reader = $this->openCsv($csv_file);
|
|
||||||
if (!$reader) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$importer = new AirportImporter();
|
$importer = new AirportImporter();
|
||||||
return $this->runImport($reader, $importer);
|
return $this->runImport($csv_file, $importer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,13 +164,8 @@ class ImportService extends Service
|
|||||||
Expense::truncate();
|
Expense::truncate();
|
||||||
}
|
}
|
||||||
|
|
||||||
$reader = $this->openCsv($csv_file);
|
|
||||||
if (!$reader) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$importer = new ExpenseImporter();
|
$importer = new ExpenseImporter();
|
||||||
return $this->runImport($reader, $importer);
|
return $this->runImport($csv_file, $importer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,14 +181,8 @@ class ImportService extends Service
|
|||||||
# TODO: Delete all from: fares
|
# TODO: Delete all from: fares
|
||||||
}
|
}
|
||||||
|
|
||||||
$reader = $this->openCsv($csv_file);
|
|
||||||
if (!$reader) {
|
|
||||||
# TODO: Throw an error
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$importer = new FareImporter();
|
$importer = new FareImporter();
|
||||||
return $this->runImport($reader, $importer);
|
return $this->runImport($csv_file, $importer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,14 +198,8 @@ class ImportService extends Service
|
|||||||
# TODO: Delete all from: flights, flight_field_values
|
# TODO: Delete all from: flights, flight_field_values
|
||||||
}
|
}
|
||||||
|
|
||||||
$reader = $this->openCsv($csv_file);
|
|
||||||
if (!$reader) {
|
|
||||||
# TODO: Throw an error
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$importer = new FlightImporter();
|
$importer = new FlightImporter();
|
||||||
return $this->runImport($reader, $importer);
|
return $this->runImport($csv_file, $importer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,13 +215,7 @@ class ImportService extends Service
|
|||||||
# TODO: Cleanup subfleet data
|
# TODO: Cleanup subfleet data
|
||||||
}
|
}
|
||||||
|
|
||||||
$reader = $this->openCsv($csv_file);
|
|
||||||
if (!$reader) {
|
|
||||||
# TODO: Throw an error
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$importer = new SubfleetImporter();
|
$importer = new SubfleetImporter();
|
||||||
return $this->runImport($reader, $importer);
|
return $this->runImport($csv_file, $importer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user