app/avatar.py
BlobError, an Exception subclass. Its codes are the ones the TypeScript SDK and the browser client use, so an error raised in your Python handler reaches a React hook with its code intact. The codes, their statuses and when each one is raised are on Errors.
BlobError and BlobErrorCode are exported from upstash_blob.
Catching it
BlobError class, so except BlobError and isinstance are all you need. BlobErrorCode is a Literal of every code, so an editor completes them.
Fields
The underlying error, when there was one, is the standard
__cause__, set with raise ... from. A move_left_a_copy carries the failed delete there.
Built-in hints
How a hint folds into the message is on Hints fold into the message.
Raising one
BlobError(code, message=None, *, hint, status, failed, etag, size, retry_after, reason). The message is positional; everything else is a keyword. Raise one from an upload handler callback to refuse an upload with that code; see Refusing.
to_dict()
BlobError. hint, failed, etag, size and retryAfter are included when they are set. reason never is.
The handler writes this body for you. Call it yourself to answer with a BlobError from a route of your own, such as one that calls put for useServerUpload:
app/main.py
BlobError also survives pickle, so it crosses a process pool or a task queue with its fields intact.
Bad options raise TypeError or ValueError
A wrong type raises aTypeError and a value that does not parse raises a ValueError, where the option is written:
Two option mistakes raise a
BlobError instead. A content_types list that is empty, or holds an entry that is not a type/subtype or one of image/*, video/* and audio/*, raises invalid_content_type_pattern, on a put or when a handler is built. A content_type that is not a media type raises invalid_input.
The upload handler turns the path errors into invalid_input, since a path built from the browser’s filename can be the client’s doing. A few handler mistakes only show up while a request runs, and raise a TypeError that the framework answers as a 500:
on_before_uploadreturned something other than aBeforeUploadResult, or astatethat is not JSON-serializable.on_before_uploadreturnedcontent_typesor amax_sizewider than the route’s; see Narrowing per user.on_upload_completereturned a value that is not JSON-serializable.- An
UploadHandlercallback returned a coroutine; see Sync or async.