8000 Adding in handling for generic row errors · ReservedDeveloper/csv-bundle@78c2d9b · GitHub
[go: up one dir, main page]

Skip to 8000 content

Commit 78c2d9b

Browse files
author
Daniel Lakes
committed
Adding in handling for generic row errors
1 parent 62d3377 commit 78c2d9b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

FileReader/Response/ReaderResponse.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ public function addErrorForField($fieldName, \Exception $error)
6060
$this->success = false;
6161
}
6262

63+
/**
64+
* add a generic error for the row
65+
*
66+
* @param Exception $error
67+
*/
68+
public function addErrorForRow(\Exception $error)
69+
{
70+
array_push($this->errors, $error);
71+
}
72+
6373
/**
6474
* clear error messages and reset success
6575
*/
@@ -117,5 +127,4 @@ public function setRowData(array $rowData)
117127

118128
return $this;
119129
}
120-
121130
}

FileReader/Response/ResponseHandler.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
namespace Nerdery\CsvBundle\FileReader\Response;
10+
use Nerdery\CsvBundle\Exception\FileInvalidRowException;
1011
use Nerdery\CsvBundle\Exception\InvalidDataFieldException;
1112

1213
/**
@@ -130,6 +131,20 @@ public function addFieldErrorForResponse($fieldKey, $fieldValue, $message = null
130131
$this->getResponse(false)->addErrorForField($fieldKey, $exception);
131132
}
132133

134+
/**
135+
* Generate a new exception for the row and
136+
* add to the error queue
137+
* @param string|null $message
138+
*/
139+
public function addRowErrorForResponse($message = null){
140+
$message = !empty($message)
141+
? $message
142+
: 'There was an error detected within the row.';
143+
144+
$exception = new FileInvalidRowException($message);
145+
$this->getResponse(false)->addErrorForRow($exception);
146+
}
147+
133148
/**
134149
* @param string|int $fieldKey - the name of the field, or key if none
135150
* @param mixed $fieldValue - the value provided for the field

0 commit comments

Comments
 (0)
0