Skip to content

Exception for broken links without status code / with status code 0 #65

@scholejo

Description

@scholejo

Hello!

We're using your SDK indirectly through this Craft CMS Plugin: https://github.com/webhubworks/craft-ohdear
Recently, I've noticed that some of the sites we built with Craft CMS and the plugin throw exceptions when checking for broken links via the SDK.

The relevant part of the stack trace looks like this:

2025-12-15 13:35:57 [web.ERROR] [TypeError] TypeError: OhDear\PhpSdk\Dto\BrokenLink::__construct(): Argument #1 ($statusCode) must be of type int, null given, called in /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/Dto/BrokenLink.php on line 19 and defined in /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/Dto/BrokenLink.php:7
Stack trace:
#0 /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/Dto/BrokenLink.php(19): OhDear\PhpSdk\Dto\BrokenLink->__construct()
#1 /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/Dto/BrokenLink.php(33): OhDear\PhpSdk\Dto\BrokenLink::fromResponse()
#2 [internal function]: OhDear\PhpSdk\Dto\BrokenLink::OhDear\PhpSdk\Dto\{closure}()
#3 /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/Dto/BrokenLink.php(33): array_map()
#4 /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/Requests/BrokenLinks/GetBrokenLinksRequest.php(27): OhDear\PhpSdk\Dto\BrokenLink::collect()
#5 /var/www/html/vendor/ohdearapp/ohdear-php-sdk/src/OhDear.php(125): OhDear\PhpSdk\Requests\BrokenLinks\GetBrokenLinksRequest->createDtoFromResponse()

I went through the code with xdebug and can confirm, that $data['status_code'] is null in OhDear\PhpSdk\Dto\BrokenLink::fromResponse(). So it seems to me that the API responds with null as status code. In the Oh Dear Dashboard, I can see that the affected broken link (external) has a status code of '0'. I guess it's just a null-check missing here.

This issue makes the CMS unusable for our clients as long as there are broken links with status code '0' in the report. I have to disable the plugin at least in parts to make the CMS work.

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions