Improve userFriendlyMessage devX (#16815)

Two challenges with error messages
- always provide a useful/meaningful error message for the end user
instead of the generic one. eg: show "Wrong password" and not "An error
occured"
- avoid technical details unless error regards a technical feature. eg:
show "An error occured" and not "Invalid post-hook payload."; but do
show "Invalid issuer URL." as it occurs while configuring SSO

What this PR does
- Make userFriendlyMessage mandatory for widely used
GraphqlQueryRunnerException and CommonQueryRunnerException, so that
developers are forced to ask themselves what the error message should
be, and as it contains very wide error codes (eg: "Bad request") which
should not be mapped to just one default message
- Keep userFriendlyMessage optional for service-specific exceptions (eg:
workflowStepExecutorException), but convert the error code to
userFriendlyMessage mapper to a switch case function with a typecheck
ensuring that all codes are mapped to a message. These default messages
are still overridable where they are thrown.
This commit is contained in:
Marie
2025-12-30 10:08:43 +01:00
committed by GitHub
parent 7522ff6675
commit 19c9f957b1
135 changed files with 1672 additions and 845 deletions
@@ -1,6 +1,7 @@
import { type MessageDescriptor } from '@lingui/core';
import { msg } from '@lingui/core/macro';
import { assertUnreachable } from 'twenty-shared/utils';
import { STANDARD_ERROR_MESSAGE } from 'src/engine/api/common/common-query-runners/errors/standard-error-message.constant';
import { CustomException } from 'src/utils/custom-exception';
export enum RelationExceptionCode {
@@ -11,15 +12,19 @@ export enum RelationExceptionCode {
MULTIPLE_JOIN_COLUMNS_FOUND = 'MULTIPLE_JOIN_COLUMNS_FOUND',
}
const relationExceptionUserFriendlyMessages: Record<
RelationExceptionCode,
MessageDescriptor
> = {
[RelationExceptionCode.RELATION_OBJECT_METADATA_NOT_FOUND]: msg`Relation object not found.`,
[RelationExceptionCode.RELATION_TARGET_FIELD_METADATA_ID_NOT_FOUND]: msg`Relation target field not found.`,
[RelationExceptionCode.RELATION_JOIN_COLUMN_ON_BOTH_SIDES]: msg`Relation has join column on both sides.`,
[RelationExceptionCode.MISSING_RELATION_JOIN_COLUMN]: msg`Missing relation join column.`,
[RelationExceptionCode.MULTIPLE_JOIN_COLUMNS_FOUND]: msg`Multiple join columns found.`,
const getRelationExceptionUserFriendlyMessage = (
code: RelationExceptionCode,
) => {
switch (code) {
case RelationExceptionCode.RELATION_OBJECT_METADATA_NOT_FOUND:
case RelationExceptionCode.RELATION_TARGET_FIELD_METADATA_ID_NOT_FOUND:
case RelationExceptionCode.RELATION_JOIN_COLUMN_ON_BOTH_SIDES:
case RelationExceptionCode.MISSING_RELATION_JOIN_COLUMN:
case RelationExceptionCode.MULTIPLE_JOIN_COLUMNS_FOUND:
return STANDARD_ERROR_MESSAGE;
default:
assertUnreachable(code);
}
};
export class RelationException extends CustomException<RelationExceptionCode> {
@@ -30,7 +35,7 @@ export class RelationException extends CustomException<RelationExceptionCode> {
) {
super(message, code, {
userFriendlyMessage:
userFriendlyMessage ?? relationExceptionUserFriendlyMessages[code],
userFriendlyMessage ?? getRelationExceptionUserFriendlyMessage(code),
});
}
}