Exceptions#

Every exception derives from PloneClientError, and every one is importable from plone_client.

Hierarchy#

Exception

Parent

Raised when

CLI exit code

PloneClientError

Exception

Base of all the others.

1

PloneConfigurationError

PloneClientError

A profile, a secret, or the URL is missing or invalid.

3

PloneReadOnlyError

PloneClientError

A read-only client is asked to change the site.

7

PloneConnectionError

PloneClientError

The site cannot be reached.

8

PloneTimeoutError

PloneConnectionError

The site does not answer in time.

8

PloneOperationError

PloneClientError

An operation of plone_client.operations stops part way; its result lists what was done, and __cause__ is the error that stopped it.

That of __cause__

PloneAPIError

PloneClientError

The site answers with an error not listed below.

1

PloneBadRequestError

PloneAPIError

400

6

PloneAuthenticationError

PloneAPIError

401

4

PloneForbiddenError

PloneAPIError

403, also for a locked item

4

PloneNotFoundError

PloneAPIError

404

5

PloneConflictError

PloneAPIError

409

6

PloneServerError

PloneAPIError

5xx

9

Attributes of PloneAPIError#

Attribute

Meaning

status_code

HTTP status of the answer.

error_type

The error type plone.restapi reports, such as NotFound or BadRequest.

message

The error message plone.restapi reports.

method

Method of the request.

url

URL of the request.

body

The decoded body of the answer.

Classes#

Exceptions raised by plone-client.

Every exception derives from PloneClientError, so a single except PloneClientError catches anything the library raises. Errors answered by the site derive from PloneAPIError and carry the status code, the error type reported by plone.restapi and the parsed body.

exception plone_client.exceptions.PloneClientError[source]#

Bases: Exception

Base class for every error raised by plone-client.

exception plone_client.exceptions.PloneConfigurationError[source]#

Bases: PloneClientError

The client, a profile or a secret is missing or invalid.

exception plone_client.exceptions.PloneReadOnlyError[source]#

Bases: PloneClientError

A request that changes the site was refused by a read-only client.

exception plone_client.exceptions.PloneConnectionError[source]#

Bases: PloneClientError

The site could not be reached.

exception plone_client.exceptions.PloneTimeoutError[source]#

Bases: PloneConnectionError

The site did not answer in time.

exception plone_client.exceptions.PloneOperationError(message, result)[source]#

Bases: PloneClientError

An operation of several requests stopped part way.

The error that stopped it is the __cause__.

Parameters:
  • message (str) – What failed.

  • result (Any) – What the operation did before it stopped: the items it created or changed and every request it sent, so a caller can clean up or resume (see OperationResult).

Return type:

None

exception plone_client.exceptions.PloneAPIError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneClientError

The site answered with an error status.

Parameters:
  • message (str) – Error message, taken from the response when possible.

  • status_code (int) – HTTP status code of the response.

  • error_type (str) – Error type reported by plone.restapi (NotFound, BadRequest, Unauthorized…), if any.

  • body (Any) – Parsed JSON body, or the response text.

  • method (str) – HTTP method of the failed request.

  • url (str) – URL of the failed request.

Return type:

None

to_dict()[source]#

Serializable summary of the error.

Returns:

Status code, error type, message, method and URL.

Return type:

dict[str, Any]

exception plone_client.exceptions.PloneBadRequestError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneAPIError

HTTP 400: invalid data, such as a validation error or a duplicated id.

Parameters:
Return type:

None

exception plone_client.exceptions.PloneAuthenticationError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneAPIError

HTTP 401: the credentials are missing, wrong or expired.

Parameters:
Return type:

None

exception plone_client.exceptions.PloneForbiddenError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneAPIError

HTTP 403: the user is not allowed to do this, or the item is locked.

Parameters:
Return type:

None

exception plone_client.exceptions.PloneNotFoundError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneAPIError

HTTP 404: there is nothing at this path.

Parameters:
Return type:

None

exception plone_client.exceptions.PloneConflictError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneAPIError

HTTP 409: the request conflicts with the current state.

Parameters:
Return type:

None

exception plone_client.exceptions.PloneServerError(message, *, status_code, error_type='', body=None, method='', url='')[source]#

Bases: PloneAPIError

HTTP 5xx: the site failed to handle the request.

Parameters:
Return type:

None

plone_client.exceptions.error_payload(error)[source]#

JSON description of an error, as the command line and MCP server report it.

Parameters:

error (PloneClientError) – The error.

Returns:

{"error": {...}} with the type and message, and the status code and URL for errors answered by the site. For an operation that stopped part way, error describes the request that failed and result what the operation had done.

Return type:

dict[str, Any]

plone_client.exceptions.error_from_response(response)[source]#

Build the exception matching an error response.

Parameters:

response (Response) – Response with a status code of 400 or more.

Returns:

An instance of the PloneAPIError subclass for the status.

Return type:

PloneAPIError