|
| 1 | +# MSC3848: Introduce errcodes for specific membership change failures. |
| 2 | + |
| 3 | +When performing an action on the C-S API, sometimes it will fail if the user is already joined to the room. In |
| 4 | +these cases, homeservers will throw a `M_FORBIDDEN` stating that the action wasn't successful. However, it's difficult |
| 5 | +to distinguish this kind of failure from insufficient permission errors (or other kinds of errors). This would be |
| 6 | +useful, as the caller can then react to the error e.g. refresh it's membership cache if it tries to invite a user |
| 7 | +that is already joined. |
| 8 | + |
| 9 | +## Proposal |
| 10 | + |
| 11 | +New `errcode` would be introduced into the error body of a response (https://spec.matrix.org/latest/client-server-api/#standard-error-response). |
| 12 | + |
| 13 | +`M_ALREADY_JOINED` would be fired when a membership action fails when the user is already joined to the room. |
| 14 | +This would cover endpoints: |
| 15 | + - [POST /_matrix/client/v3/rooms/{roomId}/invite](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidinvite) |
| 16 | + - [POST /_matrix/client/v3/rooms/knock/{roomIdOrAlias}](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3knockroomidoralias) |
| 17 | + - [PUT /_matrix/client/v3/rooms/{roomId}/state/{eventType}/{stateKey}](https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey) |
| 18 | +Note that it would not cover endpoints where trying to join a room when the user is already joined would no-op, like `POST /_matrix/client/v3/join/{roomIdOrAlias}`. |
| 19 | + |
| 20 | +`M_INSUFFICENT_POWER` would be when your user does not have the specific required power level to |
| 21 | +perform an action in the room. |
| 22 | + - [POST /_matrix/client/v3/rooms/{roomId}/invite](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidinvite) |
| 23 | + - [POST /_matrix/client/v3/rooms/knock/{roomIdOrAlias}](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3knockroomidoralias) |
| 24 | + - [POST /_matrix/client/v3/rooms/{roomId}/unban](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidban) |
| 25 | + - [POST /_matrix/client/v3/rooms/{roomId}/ban](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidban) |
| 26 | + - [POST /_matrix/client/v3/rooms/{roomId}/kick](https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidkick) |
| 27 | + - [PUT /_matrix/client/v3/rooms/{roomId}/state/{eventType}/{stateKey}](https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey) |
| 28 | + |
| 29 | + |
| 30 | +## Potential issues |
| 31 | + |
| 32 | +Changing long-established error codes in Matrix will be fraught with risk, as many clients will need updating |
| 33 | +to support the new error types. Failure to do so might lead to unexpected behaviours or confusing error messages. |
| 34 | +However, the alternative is keeping the non-specific error codes and having the |
| 35 | + |
| 36 | +## Alternatives |
| 37 | + |
| 38 | +We could introduce a second field to the error body for more specific errors, but this would likely make |
| 39 | +error handling in clients much more complicated. |
| 40 | + |
| 41 | +## Security considerations |
| 42 | + |
| 43 | +None. |
| 44 | + |
| 45 | +## Unstable prefix |
| 46 | + |
| 47 | +While this MSC is not considered stable for implementation, implementations should use `org.matrix.unstable.errcode` |
| 48 | +as a prefix to the fields on the error body. `M_FORBIDDEN` will still be emitted as a `errcode` while the |
| 49 | +MSC is unstable, and will be replaced when the spec stabilizes. |
| 50 | + |
| 51 | +## Dependencies |
| 52 | + |
| 53 | +None. |
0 commit comments