I've been trying to wrap my head around this now for 2 days and I'm stuck...
When I call my api (in the @bulkValidate function) with data that is supposed to error, Restangular is skipping my error handler and just silently failing. Then, if I try to pass the same data again or anytime after it works as expected and the error toast is properly displayed. I can see in the network that the exact same 400 message is being sent from the api in either case so I know that is working properly.
After digging through SO posts, I found that $qProvider.errorOnUnhandledRejections(false)
is letting my errors pass through to my custom error handlers, so when I gave this function a true
value, I now get errors with this message:
Error: [$sce:itype] Attempted to trust a non-string value in a content requiring a string: Context: html
which I thought was being caused by the <br/>
I'm putting in the toastr message but it happens even when I remove it and the first error is still not getting caught by my catch
regardless. I've also tried wrapping the error message in $sce.trustAsHtml as directed in this post but I still get the error.
@bulkValidate = ->
# Checked items live in approval_list
if approval_list.length > 0
orchestration.bulk_validate approval_list, host
.then (res)->
helper.displayToast 'success', 'Success', 'The selected categories have been scheduled for publishing.'
$scope.$broadcast 'refresh_queue'
.catch (err)->
console.log(err)
if err.status == 400
msg = ''
for onemsg in err.data.errors
if msg.length > 0 then msg = msg + '<br/><br/>'
msg = msg + onemsg
if err.data.num_validated != undefined
num_validated = err.data.num_validated
errorMsg = num_validated + ' categories have been scheduled for publishing<br/><br/>. Some categories could not be published due to validation errors: <br/><br/>' + msg
helper.displayToast 'error','Error', errorMsg, {timeOut: 120000, showDuration: 12000}
else
helper.displayToast 'error','Error', 'No categories were published due to validation errors: ' + msg, {timeOut: 120000, showDuration: 12000}
Any help or suggestions would be greatly appreciated!