correct errors on duplicate and invalid packages
This commit is contained in:
parent
c8b80ee27d
commit
c2ee4f8c2b
@ -39,7 +39,26 @@ class PackageController extends Controller
|
|||||||
Yii::$app->response->statusCode = 201;
|
Yii::$app->response->statusCode = 201;
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
throw new HttpException(400, json_encode($package->errors));
|
foreach ($package->errors as $attributeErrors) {
|
||||||
|
foreach ($attributeErrors as $error) {
|
||||||
|
if (strpos($error, 'has already been taken')) {
|
||||||
|
throw new HttpException(403, 'Package already registered');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($package->errors['name'])) {
|
||||||
|
throw new HttpException(400, 'Invalid Package Name: ' . implode(', ', $package->errors['name']));
|
||||||
|
}
|
||||||
|
if (isset($package->errors['url'])) {
|
||||||
|
throw new HttpException(400, 'Invalid URL: ' . implode(', ', $package->errors['url']));
|
||||||
|
}
|
||||||
|
$errors = [];
|
||||||
|
foreach ($package->errors as $attribute => $attributeErrors) {
|
||||||
|
foreach ($attributeErrors as $error) {
|
||||||
|
$errors[] = $attribute . ': ' . $error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new HttpException(400, 'Error: ' . implode(', ', $errors));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user