renoki-co / php-k8s

Unofficial PHP client for Kubernetes. It supports any form of authentication, the exec API, and it has an easy implementation for CRDs.
Apache License 2.0
307 stars 56 forks source link

Refactored HTTP exception management, with possible breaking changes: #396

Closed gplanchat closed 8 months ago

gplanchat commented 9 months ago

Refactored HTTP exception management, with possible breaking changes:

  1. transformed PhpK8sException into an interface
  2. transformed KubernetesAPIException into an interface
  3. moved the $payload property to the WithPayload trait
  4. created dedicated exceptions for every of 400, 401, 403, 404, 405, 429 HTTP response codes
  5. catch the ConnectException from Guzzle that escaped the encapsulation, now replaced with a ClusterNotReachableException

Points 1., 2. and 3.

Those points are for maximum backward compatibility.

Point 4

This point is for helping users of the library to identify the type of error that happened without having to parse Guzzle's exception messages. The code provided to the exceptions are very often at 0 and does not provide any help to discriminate error types.

Also, the original exception was lost and not provided to the newly created exception. This complexifies the debugging by hiding the real source of the error.

Point 5

An exception from Guzzle is escaping the encapsulation. This happens when the API server is not reachable through the network this includes cases like :

Possible breaking changes

If you were previously instanciating PhpK8sException or KubernetesAPIException classes, it will not be possible anymore as they have been transformed into interfaces.

Positive impacts

All your try ... catch statements will continue to work seamlessly as the new exception classes implement the PhpK8sException and KubernetesAPIException interfaces. You may however want to change your statements to use the new exception classes and ease your error management.