transloadit / uppy

The next open source file uploader for web browsers :dog:
https://uppy.io
MIT License
29.02k stars 2k forks source link

Consistent Companion error API #5436

Open mifi opened 1 month ago

mifi commented 1 month ago

Problem

Currently there is no proper, documented system in in place for passing errors from Companion to Uppy

Solution

Note that we have to be careful and try not to make this breaking changes between Uppy and Companion.

We also need to distinguish between expected and unexpected errors:

Expected errors

Expected errors are errors that are part of a normal flow and should not raise any alarm. Examples:

These kinds of errors should either be:

Related:

Unexpected errors

All other errors are errors that don't match "Expected errors". They should be logged as logger.error so that error reporting systems can pick them up and be actionable for Operations. These errors should be returned to the user with a generic error code (e.g. there is a temporary problem, please try again later).

Examples of such errors:

Alternatives

Just use a simple API where all errors are treated equally and sent to the user as a "generic error" response (but logged on the server). Then all we can do in Uppy is to ask the user to try again (which might sometimes work, but sometimes not due to the nature of the error). Then the user would contact the company using Uppy which will make an issue here and we have to solve the issue.

yaegor commented 1 month ago

Thank you for taking a generic approach to the error reporting. I'd just add a use case from my original issue #4079: I do want to show a custom error message specific to my app to the user. I guess considering the i18n it should take reporting an error code (and idealy also some message or a set of attributes/values) in the server API and then on the client translating that error code and additional data to a custom message for the UI to show that to the user. (updated - added "on the client")

mifi commented 1 month ago

Not sure if the backend should do the translation, because we already do that in the frontend. Maybe we can instead define a certain error type that the server that companion connects to can respond with, and companion will then forward them to uppy in the standard error structure. Maybe this error can contain a special error code (in a user-defined error code range or in a special vendorCode property). Then in Uppy we can provide a way to extend i18n by either: