yorkie-team/yorkie

Provide detailed error codes for enhancing error handling from Client

Closed this issue · 0 comments

What would you like to be added:

Currently, the server sends Error Code to the client to indicate error code, such as FailedPrecondition, in a simplistic manner. This makes it challenging for clients to differentiate and handle individual situations effectively.

  • // InvalidArgument means the request is malformed.
    converter.ErrPackRequired: connect.CodeInvalidArgument,
    converter.ErrCheckpointRequired: connect.CodeInvalidArgument,
    time.ErrInvalidHexString: connect.CodeInvalidArgument,
    time.ErrInvalidActorID: connect.CodeInvalidArgument,
    types.ErrInvalidID: connect.CodeInvalidArgument,
    clients.ErrInvalidClientID: connect.CodeInvalidArgument,
    clients.ErrInvalidClientKey: connect.CodeInvalidArgument,
    key.ErrInvalidKey: connect.CodeInvalidArgument,
    types.ErrEmptyProjectFields: connect.CodeInvalidArgument,
    // NotFound means the requested resource does not exist.
    database.ErrProjectNotFound: connect.CodeNotFound,
    database.ErrClientNotFound: connect.CodeNotFound,
    database.ErrDocumentNotFound: connect.CodeNotFound,
    database.ErrUserNotFound: connect.CodeNotFound,
    // AlreadyExists means the requested resource already exists.
    database.ErrProjectAlreadyExists: connect.CodeAlreadyExists,
    database.ErrProjectNameAlreadyExists: connect.CodeAlreadyExists,
    database.ErrUserAlreadyExists: connect.CodeAlreadyExists,
    // FailedPrecondition means the request is rejected because the state of the
    // system is not the desired state.
    database.ErrClientNotActivated: connect.CodeFailedPrecondition,
    database.ErrDocumentNotAttached: connect.CodeFailedPrecondition,
    database.ErrDocumentAlreadyAttached: connect.CodeFailedPrecondition,
    database.ErrDocumentAlreadyDetached: connect.CodeFailedPrecondition,
    documents.ErrDocumentAttached: connect.CodeFailedPrecondition,
    packs.ErrInvalidServerSeq: connect.CodeFailedPrecondition,
    database.ErrConflictOnUpdate: connect.CodeFailedPrecondition,
    // Unimplemented means the server does not implement the functionality.
    converter.ErrUnsupportedOperation: connect.CodeUnimplemented,
    converter.ErrUnsupportedElement: connect.CodeUnimplemented,
    converter.ErrUnsupportedEventType: connect.CodeUnimplemented,
    converter.ErrUnsupportedValueType: connect.CodeUnimplemented,
    converter.ErrUnsupportedCounterType: connect.CodeUnimplemented,
    // Unauthenticated means the request does not have valid authentication
    auth.ErrNotAllowed: connect.CodeUnauthenticated,
    auth.ErrUnexpectedStatusCode: connect.CodeUnauthenticated,
    auth.ErrWebhookTimeout: connect.CodeUnauthenticated,
    database.ErrMismatchedPassword: connect.CodeUnauthenticated,

It is necessary to directly transmit error codes generated by the server to allow clients to respond accordingly to each specific error. After transmitting the error codes, each error case needs to be handled individually by clients.

Why is this needed:

To improve client-side error handling and responsiveness to server-generated errors.