Address results not checked for errors - page produces: Warning: Undefined array key "Collection"

Created on 9 June 2025, 3 days ago

Problem/Motivation

I'm getting a lot of errors and no results for the page for a single address.

The errors start with:

Warning: Undefined array key "Collection" in Drupal\localgov_waste_collection_whitespace_provider\Plugin\DataProvider\WhitespaceDataProvider->getCollections() (line 282 of /var/www/html/repos/localgov_waste_collection/modules/localgov_waste_collection_whitespace_provider/src/Plugin/DataProvider/WhitespaceDataProvider.php).

The code in question is this:

      $json = json_encode($collectionsXml);
      $monthCollections = json_decode($json, TRUE);

      foreach ($monthCollections["Collection"] as $collection) {

The problem is that the XML body being loaded up doesn't have any collections, but this error message instead:

  <s:Body>
    <GetCollectionByUprnAndDateResponse xmlns="http://webservices.whitespacews.com/">
      <GetCollectionByUprnAndDateResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <CodeDescription>No results returned</CodeDescription>
        <ErrorCode>6</ErrorCode>
        <ErrorDescription>No results returned</ErrorDescription>
        <SuccessFlag>false</SuccessFlag>
        <Collections i:nil="true"/>
      </GetCollectionByUprnAndDateResult>
    </GetCollectionByUprnAndDateResponse>
  </s:Body>

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @joachim
  • 🇬🇧United Kingdom joachim
  • 🇬🇧United Kingdom danchamp Angus

    @joachim Do you know which version of the Whitespace API is in use for your site? Do you have the API documentation?

    The plugin was written for a Council using v11.0, but I know that changes were introduced in v11.1 (such as support for date ranges beyond a single month), and there may be later versions with more breaking changes.

  • 🇬🇧United Kingdom joachim

    > Do you know which version of the Whitespace API is in use for your site?

    No, I'm afraid.

    > Do you have the API documentation?

    No -- I've looked on the Whitespace website for documentation on their API, and I can't find anything (and it crashes!)

  • 🇬🇧United Kingdom joachim

    It was a domain problem -- I was connecting to an environment that didn't have up-to-date collections.

    Catching of Whitespace exceptions has been added to 🐛 Guzzle exceptions in Whitespace provider are not caught Active , but the code here still needs to check for the case where the returned XML has:

            <Collections i:nil="true"/>
    

    I can't figure out how to get that by inspecting the $collectionsXml from:

    $collectionsXml = $xml
            ->children('s', TRUE)
            ->Body
            ->children('http://webservices.whitespacews.com/')
            ->GetCollectionByUprnAndDateResponse
            ->GetCollectionByUprnAndDateResult
            ->Collections;
    

    SO says I should be able to cast $collectionsXml to bool and get FALSE, but that's not working.

  • 🇬🇧United Kingdom joachim

    Added checking of the error code.

    I'm having it return an empty array at the moment. I'm not sure if this is the best thing, as that means the controller will show:

    No collection schedule found

    We could not retrieve the collection schedule for this property. Please check this is a domestic property, and contact us if the problem continues.

    -- is that the most accurate thing to show the user?

Production build 0.71.5 2024