Better error reporting for failed save on BPE

This commit is contained in:
Rob H
2014-08-08 14:02:15 +10:00
parent d8c1823328
commit 5fea15e8a9
3 changed files with 22 additions and 5 deletions

View File

@@ -271,7 +271,12 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
$scope.updateVariantLists(data.products)
$timeout -> $scope.displaySuccess()
).error (data, status) ->
$scope.displayFailure "Server returned with error status: " + status
if status == 400 && data.errors? && data.errors.length > 0
errors = error + "\n" for error in data.errors
alert "Saving failed with the following error(s):\n" + errors
$scope.displayFailure "Save failed due to invalid data"
else
$scope.displayFailure "Server returned with error status: " + status
$scope.packProduct = (product) ->
@@ -336,7 +341,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
$scope.displayFailure = (failMessage) ->
$scope.setMessage $scope.updateStatusMessage, "Saving failed. " + failMessage,
color: "#DA5354"
, 10000
, false
$scope.displayDirtyProducts = ->

View File

@@ -33,7 +33,11 @@ Spree::Admin::ProductsController.class_eval do
if product_set.save
redirect_to "/api/products/bulk_products?page=1;per_page=500;#{bulk_index_query}"
else
render :nothing => true, :status => 418
if product_set.errors.present?
render json: { errors: product_set.errors }, status: 400
else
render :nothing => true, :status => 500
end
end
end

View File

@@ -842,14 +842,22 @@ describe "AdminProductEditCtrl", ->
expect(DirtyProducts.clear).toHaveBeenCalled()
expect($scope.updateVariantLists).toHaveBeenCalled()
it "runs displayFailure() when post returns error", ->
it "runs displayFailure() when post returns an error", ->
spyOn $scope, "displayFailure"
$scope.products = "updated list of products"
$httpBackend.expectPOST("/admin/products/bulk_update").respond 404, "updated list of products"
$httpBackend.expectPOST("/admin/products/bulk_update").respond 500, "updated list of products"
$scope.updateProducts "updated list of products"
$httpBackend.flush()
expect($scope.displayFailure).toHaveBeenCalled()
it "shows an alert with error information when post returns 400 with an errors array", ->
spyOn(window, "alert")
$scope.products = "updated list of products"
$httpBackend.expectPOST("/admin/products/bulk_update").respond 400, { "errors": ["an error"] }
$scope.updateProducts "updated list of products"
$httpBackend.flush()
expect(window.alert).toHaveBeenCalledWith("Saving failed with the following error(s):\nan error\n")
describe "fetching a product by id", ->
it "returns the product when it is present", ->
product = {id: 123}