Skip to main content

Error handling

A failing Partner API request on REST returns a JSON body carrying a message; on gRPC it ends with a status code and error details, as gRPC status codes describes. On REST, a validation failure adds a details array naming every field that was rejected, so a malformed request can be corrected in one pass rather than one field at a time.

Three parts of an error are contract and safe to branch on: the HTTP status code, the reason the body carries for some failures, and the reason on each entry in details. Everything else, including all human-readable text, may change between releases, so code that handles errors branches only on these three. The one exception is a gRPC call rejected by the rate limit, which is recognized by its status message.

Status codes​

400The request was rejected. On a validation failure, every offending field is listed.On Embed, Record writes and a List jobs page_size that is not validNo, with one exception below
401The access token is missing, expired, or invalid.NoAfter obtaining a new token
403The credential is valid but not permitted to perform this operation.NoNo
404The job or Signature does not exist, was registered by another Partner, or has no Record attached.NoNo
409The Signature is revoked, so its Record can no longer be modified.NoNo
412The If-Match precondition did not match the Signature's current revision. The Record was not modified.NoOnce, after re-reading the Record
429The request exceeded the rate limit and was rejected before it reached the API. The body is HTML.NoWith an HTML body: yes, any operation, with the backoff in Recover from a rejection. With a JSON body, too many video jobs are running: once one of them has finished
500An internal failure.NoNo. If 500 recurs on later requests, escalate with the request_id.
503A dependency is temporarily unavailable. With reason MEDIA_STAGING_FULL, an Embed or Lookup submit was refused because SASHA is holding as much submitted media as it can, and no job was created.NoMEDIA_STAGING_FULL: submit again after the Retry-After wait, as in Media waiting to be processed. Otherwise only an operation safe to repeat, as in Retrying a request

Only 400 carries details, and only where the endpoint validates the request: Embed, PUT Record, PATCH Record, and List jobs when page_size is not a whole number of 0 or more. Every other failure from the API carries message, and a top-level reason when the failure has a named cause, such as MEDIA_STAGING_FULL on a 503, or PAGE_TOKEN_INVALID on a 400 from List jobs. 401 and 403 return a body of message only, with no request_id — read the SASHA-Request-ID header instead.

The exception to "do not retry a 400": an Embed or Lookup submitted with a media_url returns 400 when SASHA cannot fetch that URL, which is a failure of the remote host rather than of the request. That one is worth a single retry; every validation failure is deterministic and is not.

404 covers an unknown Signature, one registered by a different Partner, and one that has no Record attached. The first two are deliberately indistinguishable: separating them would tell a caller which SignatureIDs exist.

Every response from the API, successful or not, carries a SASHA-Request-ID header identifying that request. It joins a Partner's call to the server-side logs, and it is the first thing SASHA support asks for. A request rejected by the rate limit never reached the API, so its response has none.

gRPC status codes​

On gRPC, a failing call ends with a status code and a status message. Where the protos name a reason, the call also carries error details in the standard grpc-status-details-bin trailer, which mainstream gRPC libraries decode.

INVALID_ARGUMENTThe request was rejected. A rejected Record lists every offending field in a google.rpc.BadRequest.400
UNAUTHENTICATEDThe access token is missing, invalid or expired. An expired token carries the reason TOKEN_EXPIRED.401
PERMISSION_DENIEDThe token does not grant the permission the RPC requires.403
NOT_FOUNDThe job or Signature does not exist, or belongs to another Partner.404
FAILED_PRECONDITIONThe Signature is revoked, or expected_revision did not match the current revision.409 or 412
UNAVAILABLEA temporary failure, the rate limit, or, with the reason MEDIA_STAGING_FULL, a submit refused before a job was created.429 or 503
INTERNALAn internal failure.500

Two detail messages from google/rpc/error_details.proto carry the machine-readable part:

  • google.rpc.ErrorInfo names a reason, such as TOKEN_EXPIRED or MEDIA_STAGING_FULL, with the domain partner-api.sasha.eu. A reason an integration does not recognize is handled as the general case of its status code.
  • google.rpc.BadRequest lists the rejected fields of a Record in field_violations. Each entry has the same field, reason and description as a REST details entry, except that field uses proto field names rooted at the request, such as record.purchase_url. At most 20 violations are reported. The reason catalogue applies, except REQUIRED, INVALID_TYPE and UNKNOWN_FIELD, which a typed gRPC request cannot cause.

The status message is the fallback for a client that does not read the trailer: on a validation failure it is the first violation's description, suffixed with (+N more). Call the gRPC API shows how each failure looks from a client.

Retrying a request​

A request rejected by the rate limit did no work, so any operation can be sent again after it, with the slower backoff in Recover from a rejection. The rest of this section is about every other failure.

An automatic retry is safe only when both of these hold:

  • It failed with a status that says "not now": gRPC UNAVAILABLE without 429 Too Many Requests in its status message, or REST 503.
  • The operation is marked safe to repeat. Repeating it has the same effect as sending it once, except that a repeated Record write moves the revision on again.
Get an access tokenPOST /oauth/tokenAuthenticateWithClientCredentialIDEMPOTENT
Read a RecordGET /signature/{signature_id}/recordGetSignatureRecordNO_SIDE_EFFECTS
Write or delete a RecordPUT, PATCH and DELETE /signature/{signature_id}/recordUpdateSignatureRecordIDEMPOTENT
Read a jobGET /jobs/{job_id}GetJobNO_SIDE_EFFECTS
List jobsGET /jobsListJobsNO_SIDE_EFFECTS

The last column is the idempotency_level option the RPC carries in partner_api.proto.

A client that retries those operations follows this policy:

  • At most 4 attempts in total, the first request included.
  • Wait 100 ms before the first retry, and double the wait before each further one, up to 1 second.
  • Randomize each wait between half of it and all of it, so that many clients rejected at the same moment do not retry in step.
  • Keep every attempt inside the deadline or timeout of the original call. A retry that cannot finish before then is not sent.
  • Never retry a streaming call that creates a job: EmbedSignatureFromData and LookupSignatureFromData. A WatchJob stream that ended with an error can be called again, because WatchJob only reads the job, as Follow the job describes.

A conditional Record write whose first attempt was applied, but whose response was lost, reports 412 on the retry, because the first attempt already moved the revision on. So a 412 on a retry calls for a re-read of the Record before the write is treated as failed.

The other operations carry no such mark: submitting an Embed or a Lookup job, by URL or as an upload, and WatchJob. A client must never retry a submit automatically. A WatchJob that ended early is called again, as the rule above describes. A request that failed with 503, or with an UNAVAILABLE that is not a rate limit, may still have been carried out. The Partner API does not recognize a repeated submit as the same request, so a retried Embed submit can create a second job and register a second Signature, which may be billed.

Media waiting to be processed​

An Embed or Lookup submit that sends an image, by media_url or as an upload, is refused when SASHA is already holding as much submitted media as it can until jobs it has accepted finish processing. The request is valid, but no job is created. Space returns as those jobs complete.

REST503 with a Retry-After header and "reason": "MEDIA_STAGING_FULL" in the ErrorResponse body
gRPCUNAVAILABLE with the reason MEDIA_STAGING_FULL in a google.rpc.ErrorInfo of domain partner-api.sasha.eu, carried in the grpc-status-details-bin trailer, and a retry-after trailer

Retry-After and retry-after hold the number of seconds to wait. Like a request rejected by the rate limit, this refused submit is safe to send again, because no job was created: the same request sent again cannot create a second job or register a second Signature. A client waits at least that many seconds, then submits the same request again. If it is refused the same way, the client waits again before the next attempt. If submits are still refused after five minutes, the client stops and the Partner contacts support@sasha.eu with the request_id.

A client branches on the reason, not on the status alone. A submit refused with 503, or with an UNAVAILABLE that has no reason and no 429 Too Many Requests in its status message, may already have been carried out, so the advice in Retrying a request applies to it: retry it only if a second job is acceptable.

Jobs fail after the request succeeds​

Embed and Lookup are asynchronous. A 200 on the submit means the job was accepted, not that it worked. The media is processed afterwards, and a failure arrives on the completed job as status: "failed" with an error object, either on a poll of GET /jobs/{job_id} or on the callback. An integration that only handles HTTP status codes will treat a failed job as a success.

The table lists every error.code an image job produces.

image_already_protectedThe image already carries a SASHA Signature.
image_load_failedThe media is not a valid image, or is in a format SASHA does not process.
image_too_largeThe image exceeds the size SASHA processes. See Supported formats.
image_too_smallThe image is below the minimum size.
internalAn internal failure. Retry the job; if it persists, escalate with the request_id of the submit.

Only internal is worth retrying. The other four are properties of the media, so the same media fails the same way.

A media_url that cannot be fetched does not reach this stage: the download happens during the submit, so it fails the request with 400 rather than the job.

Error response shape​

A failing request to the Signature, Job or Record endpoints returns an ErrorResponse:

{
"message": "purchase_url must use the https: protocol (+2 more)",
"request_id": "8f14e45f-ceea-467a-9f0b-2b3a2c5a7d61",
"details": [
{
"field": "purchase_url",
"reason": "UNSUPPORTED_SCHEME",
"description": "purchase_url must use the https: protocol"
}
]
}
JSON
messagealwaysHuman-readable summary. On a validation failure it is the first details entry's description, suffixed with (+N more) when the request has more than one violation.
request_idwhen availableMirrors the SASHA-Request-ID response header.
reasonwhen the failure has a named causeA machine-readable cause to branch on, such as MEDIA_STAGING_FULL. Absent on validation failures, whose causes are in details. A value an integration does not recognize is handled as the general case of the HTTP status.
detailsvalidation failures onlyEvery field that was rejected, up to 20 entries.

The /oauth/token endpoint is the exception: it returns the RFC 6749 error shape, error and an optional error_description, plus request_id. See Authentication.

Field violations​

Each details entry names one rejected field:

  • field — the path of the offending field, in request-body naming. Array entries are indexed and map entries are keyed: purchase_url, allowed_publish_urls[2], custom_fields["asset_id"].string_value.
  • reason — a machine-readable cause. This is the value to branch on.
  • description — a human-readable explanation. It never echoes the submitted value, so it is safe to log and to surface in a Partner's own error reporting.

A request with several problems reports all of them at once:

{
"message": "share_state must be one of: private, unrestricted, restricted (+2 more)",
"request_id": "2c3f9b7d-5a41-4a53-8f2e-9b7a1c0d4e62",
"details": [
{
"field": "share_state",
"reason": "UNKNOWN_VALUE",
"description": "share_state must be one of: private, unrestricted, restricted"
},
{
"field": "allowed_publish_urls[1]",
"reason": "INVALID_PATTERN",
"description": "allowed_publish_urls[1]: wildcard is only allowed as the leftmost label"
},
{
"field": "purchaseUrl",
"reason": "UNKNOWN_FIELD",
"description": "purchaseUrl is not a field of this request; did you mean purchase_url? (this API uses snake_case field names)"
}
]
}
JSON

Reason catalogue​

The FieldViolation schema in the REST API reference is the authoritative list: it is generated from the API specification and gains new values as they are introduced. This table explains what each current value means, and is the copy that goes stale first.

REQUIREDA field the request cannot omit was not provided.
INVALID_TYPEThe value has the wrong JSON type for the field.
INVALID_FORMATThe value has the right type but is not well-formed, for example an unparsable URL or timestamp, or a fixed-length value of the wrong length.
UNSUPPORTED_SCHEMEA URL uses a scheme the field does not accept. Only https is accepted.
FORBIDDEN_USERINFOA URL carries userinfo (user:password@), which is never accepted.
FORBIDDEN_HOSTA URL points at a host the field does not accept, such as an IP literal or localhost.
TOO_LONGThe value is longer than the field allows.
TOO_MANYThe list or map holds more entries than the field allows.
INVALID_CHARACTERSThe value contains characters the field does not accept, such as control characters.
UNKNOWN_VALUEThe value is not one of the values the field defines, for example an unknown share_state.
OUT_OF_RANGEThe value is outside the range the field allows, for example a number below its minimum or above its maximum.
NOT_ALLOWED_HEREThe field is well-formed but not allowed in this combination, for example a distribution field on a private Record.
EXACTLY_ONE_REQUIREDExactly one of a group of mutually exclusive properties must be set, for example the typed value of a custom_fields entry.
UNKNOWN_FIELDThe body carries a field the endpoint does not define — commonly a misspelling, or a camelCase spelling of a snake_case field.
EMPTYThe value is present but empty where a value is required.
INVALID_PATTERNA URL pattern is malformed and cannot be interpreted.

The set is closed but may be extended, so an unrecognized reason means a value newer than the integration, not a malformed response. Treating it as a generic validation failure keeps an integration working across releases; failing hard on it does not.

Field naming​

The REST request body uses snake_case field names, matching the API specification exactly. Clients generated by protoc-gen-es present the same fields camelCased — purchaseUrl in gRPC is purchase_url in JSON. Sending the camelCase spelling to the REST API produces an UNKNOWN_FIELD violation naming the correct spelling.

Unknown fields on a Record write are rejected rather than ignored. This is deliberate: PUT /signature/{signature_id}/record replaces the whole Record, so a misspelled field name would otherwise be silently dropped, clearing the value it was meant to set.