tamaki.mes.permissions.extractPermissionExceptionDetails
Description
Parses a permission exception and returns its components.
- If the exception is not a permission exception, returns an empty dictionary
{}. - If it is a permission exception but its message does not match the expected format, returns an error string.
- Otherwise returns a dictionary describing who was denied and what permission they needed.
Syntax
tamaki.mes.permissions.extractPermissionExceptionDetails(exception)
Parameters
| Parameter | Type | Nullable | Description |
|---|---|---|---|
exception | Exception | False | The caught permission exception. |
Returns
On a successful parse, a dictionary with the following keys:
| Key | Type | Description |
|---|---|---|
username | String | The user that was denied access. |
className | String | The fully-qualified class the called method belongs to. |
method | String | The method that required the permission. |
permissions | List | The permissions, one of which the user must have. |
Returns an empty dictionary {} if the exception is not a permission exception, or an error string
if the message cannot be parsed.
Code Examples
try:
system.mes.material.saveMaterial(**material)
except Exception as e:
details = tamaki.mes.permissions.extractPermissionExceptionDetails(e)
if details:
print(details["username"], "needs one of", details["permissions"])