Skybrud Redirects
# help-with-umbraco
r
I am using the awsome Skybrud Redirects package from @Anders Bjerner as I normally do. But I am not seeing anything in the list view. (screenshot) I am running
Umbraco 13.5.1
and
Skybrud.Umbraco.Redirects 13.0.4
. I am getting a javascript error in the console. The error is being thrown in Dashboards/Default.js and says "r.data.items.forEach is not a function"
Copy code
angular.js:15697 TypeError: r.data.items.forEach is not a function
    at Default.js?d=638639903000000000:181:22
    at angular.js:18075:37
    at m.$digest (angular.js:19242:15)
    at m.$apply (angular.js:19630:13)
    at k (angular.js:13473:36)
    at v (angular.js:13730:7)
    at y.onload (angular.js:13635:9) 'Possibly unhandled rejection: {}'
Copy code
skybrudRedirectsService.getRootNodes().then(function (r) {
      r.data.items.forEach(function (rootNode) {
          vm.rootNodes.push(rootNode);
      });
  });
Notice in the screen shot - I do have multiple root nodes When I check in the database directly, I do see many rows have been created by our content editors (screenshot) Anyone have any thoughts? https://cdn.discordapp.com/attachments/1293206600181612598/1293206600672219296/image.png?ex=67068800&is=67053680&hm=3596f94c2ba8345c52ad7d0be01c8213af3ee8f6e8b1f7813bdafd59deeed0b8& https://cdn.discordapp.com/attachments/1293206600181612598/1293206600940781660/image.png?ex=67068800&is=67053680&hm=f8875653dbbfae1483d11747fa1b8448d32d59e4a4b878c85f1ba12da95b1d00&
Ok - so found a fix for our site. Because this is such a widely used package I'm not sure if this is something with newer versions of Umbraco, or just something oddly configured about our site, so I'm reluctant to submit a PR. @Anders Bjerner if this makes sense let me know and I'll be happy to submit it for review. Here’s a summary of the changes made to the code and the reasoning behind them: Changes: Check if
r.data.items
is an array: In several places where the code assumes
r.data.items
is an array, we added a check using
Array.isArray(r.data.items)
to confirm this before iterating over it. Fallback to
$values
property if items is not an array: If
r.data.items
is not an array but has a
$values
property, the code now checks if
r.data.items.$values
is an array and uses that instead. Set an empty array as a default: If neither
r.data.items
nor
r.data.items.$values
is an array, the code safely sets the relevant variable (e.g., vm.redirects) to an empty array to prevent runtime errors. Why These Changes Were Made: Avoiding runtime errors: The original code assumes that
r.data.items
is always an array, but if it isn't (e.g., null, undefined, or an object with
$values
), trying to iterate over it would throw an error. These changes ensure the code only attempts iteration when items is actually a valid array. Handling different data structures: Some API responses may return data structures with a
$values
property (e.g., serialized collections), so the code now gracefully handles such cases. Fail-safe implementation: By setting default empty arrays when no valid array is found, the code avoids unexpected crashes and keeps the system functioning even in edge cases. This logic was added in a few different files, but this is what got us up and running. Happy to share code if anyone needs it. Since it has awareness of trying to use the original or alternate way of checking items it should hopefully backward compatible as well.
a
My best bet would be that you have something that changes the JSON format returned by the API (although I have already covered a bunch of scenarios), or that you have something intercepting the request. Can you share what the response from
/umbraco/backoffice/Skybrud/Redirects/GetRedirects
looks like?
r
"...that you have something intercepting the request." - I do indeed have a custom middleware. Shoot!! I bet that's it. I'll get the project set back up and let you know
18 Views