Fix 'Attempt to read property metadata on null' in Webhooks controller#586
Fix 'Attempt to read property metadata on null' in Webhooks controller#586proteusbr1 wants to merge 1 commit intopagarme:masterfrom
Conversation
This commit adds safe property access (null coalescing) for webhook payload data, specifically preventing errors when 'data->order' is missing in the webhook body.
|
Por favor, catalogue-o seguindo as instruções nesta documentação. [Via VPN]. 💁 Qualquer problema ou dúvida, estamos no Slack, basta abrir um ticket no canal #help-foundation-platform. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a null pointer warning in the Webhooks controller that occurred when webhook payloads lacked a complete order structure. The fix extracts code and metadata properties safely using null coalescing operators before passing them to orderByWoocommerce().
Key changes:
- Added null-safe extraction of
$codefrom webhook payload - Added null-safe extraction of
$metadatafrom nested order structure
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $code = $body->data->code ?? null; | ||
| $metadata = $body->data->order->metadata ?? null; |
There was a problem hiding this comment.
The null coalescing operator only protects against the final property being null, not intermediate properties. If $body->data is null, this will still produce a "Attempt to read property on null" warning. Consider using the nullsafe operator ?-> instead, or check if $body->data exists first. For example: $code = $body->data?->code ?? null; and $metadata = $body->data?->order?->metadata ?? null;
Qual o tipo de PR é esse? (marque todos os aplicáveis)
Descrição
Este PR resolve o
Warning: Attempt to read property "metadata" on nullemWebhooks::handle_requests. O erro acontecia quando o payload do webhook não continha a estrutura completa de pedido (data->order).Alterações realizadas:
$codee$metadatausando o operador de null coalescing (?? null).orderByWoocommercesem gerar erros fatais/warnings.Cenários testados