Loading…
Loading…
Set a custom error response shape for a specific API operation. This override is configured at the operation level and can only be applied to draft
The ErrorShapeApplyService provides a mechanism for API publishers to set a custom error response shape for a single API operation. This allows for fine-grained control over the structure of error payloads returned by the gateway, overriding system-level defaults.
When the API platform generates an error response, it follows a resolution chain to find the appropriate shape:
s2r-default.This service modifies the first link in that chain. The override applies to the entire error body; per-field error shape overrides are not supported.
Configuration changes are only permitted on service versions that are in a draft state. Once a service version is active, its operations, including their error shape overrides, become immutable.
The apply method orchestrates the process of validating and persisting an operation-specific error shape override. The process is transactional.
sequenceDiagram
participant Caller
participant ErrorShapeApplyService
participant Database
Caller->>ErrorShapeApplyService: apply(operationId, overrideValue)
activate ErrorShapeApplyService
Note over ErrorShapeApplyService: 1. Normalize override value
Note over ErrorShapeApplyService: 2. Load operation metadata
ErrorShapeApplyService->>Database: SELECT from s2r_operation, s2r_service_version
Database-->>ErrorShapeApplyService: Operation metadata (key, version status)
Note over ErrorShapeApplyService: 3. Validate service version is 'draft'
alt Validation fails
ErrorShapeApplyService-->>Caller: ApplyValidationException
end
Note over ErrorShapeApplyService: 4. Update operation mapping
ErrorShapeApplyService->>Database: UPDATE s2r_operation_mapping SET error_shape_override = ?
Database-->>ErrorShapeApplyService: Update count
alt Update fails (0 rows)
ErrorShapeApplyService-->>Caller: ApplyValidationException
end
ErrorShapeApplyService-->>Caller: ApplyResult
deactivate ErrorShapeApplyServiceThe sequence of operations is as follows:
operationOverride string is normalized. It is trimmed of whitespace. If the value is null, an empty string, or whitespace-only, it is treated as null, which clears any existing override. The normalized value is then compared case-insensitively against a list of valid modes. If it's not a valid mode, the request fails.operationId, including its operationKey and the status of its parent service version (is_active, status).is_active is false) and has a status of draft. If these conditions are not met, the request is rejected.UPDATE statement against the s2r_operation_mapping table. It sets the error_shape_override column to the normalized value for the given operation_id. The update is scoped to the authenticated tenant and only applies to mappings where is_active is true.ApplyResult object containing the operationId, the operation's operationKey, and the normalized override value that was applied.To set or clear an error shape override, invoke the apply method with the target operation's ID and the desired override mode.
This conceptual example shows how the service method is called.
// Given an instance of ErrorShapeApplyService
ErrorShapeApplyService service = new ErrorShapeApplyService(jdbcTemplate);
// The unique identifier for the target operation
UUID targetOperationId = UUID.fromString("a1b2c3d4-e5f6-7890-1234-567890abcdef");
// The desired error shape mode, e.g., "custom-verbose"
String overrideMode = "custom-verbose";
// Apply the override
try {
ApplyResult result = service.apply(targetOperationId, overrideMode);
System.out.println("Successfully applied override '" + result.operationOverride() +
"' to operation " + result.operationKey());
} catch (ApplyValidationException e) {
System.err.println("Failed to apply override: " + e.getMessage());
}
// To clear an override, pass null
ApplyResult clearedResult = service.apply(targetOperationId, null);
A successful call returns an ApplyResult object, confirming that the update was persisted. The object contains the following fields:
| Field | Type | Description |
|---|---|---|
operationId | UUID | The unique identifier of the operation that was updated. |
operationKey | String | The key or name of the operation. |
operationOverride | String | The normalized override value that was applied. May be null. |
The service exposes a single method, apply.
apply(UUID operationId, String operationOverride)Applies an error shape override to a specific operation.
IMPORTANT
This action is only possible on operations belonging to a service version that is in a draft state and is not active.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
operationId | UUID | Yes | — | The unique identifier of the target operation. |
operationOverride | String | No | null | The name of the error shape mode to apply. Must be one of the configured valid modes. Passing null or an empty string will remove the existing override. The source does not specify the list of valid modes, but indicates they are lowercase or kebab-case strings. |
Returns an ApplyResult object upon success.
ApplyValidationException: Thrown if the request fails validation. See the Troubleshooting section for details on specific error codes.When a call to apply fails, it throws an ApplyValidationException containing a machine-readable error code and a descriptive message.
| Error Code | Message Fragment | Cause |
|---|---|---|
S2R-VAL-0499 | invalid-error-shape-mode | The operationOverride string is not one of the recognized valid modes. The check is case-insensitive. |
S2R-ADM-0404 | operation-not-found | The provided operationId does not correspond to any operation in the system for the authenticated tenant. |
S2R-ADM-0404 | no-active-operation-mapping | An active mapping for the given operationId could not be found. The update query affected zero rows. This can happen if the operation exists but its mapping is marked as inactive. |
S2R-ADM-0410 | mapping-immutable | The operation belongs to a service version that is not in a draft state or is currently active. Overrides can only be applied to editable service versions. To make this change, a new draft version of the service must be created. |