0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

chore(connector-core): connector error codes use i18n key as enum string literals (#1833)

This commit is contained in:
Darcy Ye 2022-08-31 17:12:13 +08:00 committed by GitHub
parent fa51b96255
commit 923bedcda4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 86 deletions

View file

@ -32,18 +32,18 @@ export type ConnectorMetadata = {
};
export enum ConnectorErrorCodes {
General = 'General',
InvalidMetadata = 'InvalidMetadata',
InvalidConfigGuard = 'InvalidConfigGuard',
InsufficientRequestParameters = 'InsufficientRequestParameters',
InvalidConfig = 'InvalidConfig',
InvalidResponse = 'InvalidResponse',
TemplateNotFound = 'TemplateNotFound',
NotImplemented = 'NotImplemented',
SocialAuthCodeInvalid = 'SocialAuthCodeInvalid',
SocialAccessTokenInvalid = 'SocialAccessTokenInvalid',
SocialIdTokenInvalid = 'SocialIdTokenInvalid',
AuthorizationFailed = 'AuthorizationFailed',
General = 'general',
InvalidMetadata = 'invalid_metadata',
InvalidConfigGuard = 'invalid_config_guard',
InsufficientRequestParameters = 'insufficient_request_parameters',
InvalidConfig = 'invalid_config',
InvalidResponse = 'invalid_response',
TemplateNotFound = 'template_not_found',
NotImplemented = 'not_implemented',
SocialAuthCodeInvalid = 'social_auth_code_invalid',
SocialAccessTokenInvalid = 'social_invalid_access_token',
SocialIdTokenInvalid = 'social_invalid_id_token',
AuthorizationFailed = 'authorization_failed',
}
export class ConnectorError extends Error {

View file

@ -105,7 +105,7 @@ describe('koaConnectorErrorHandler middleware', () => {
await expect(koaConnectorErrorHandler()(ctx, next)).rejects.toMatchError(
new RequestError(
{
code: 'connector.oauth_code_invalid',
code: 'connector.social_auth_code_invalid',
status: 401,
},
{ message }
@ -123,7 +123,7 @@ describe('koaConnectorErrorHandler middleware', () => {
await expect(koaConnectorErrorHandler()(ctx, next)).rejects.toMatchError(
new RequestError(
{
code: 'connector.invalid_access_token',
code: 'connector.social_invalid_access_token',
status: 401,
},
{ message }
@ -141,7 +141,7 @@ describe('koaConnectorErrorHandler middleware', () => {
await expect(koaConnectorErrorHandler()(ctx, next)).rejects.toMatchError(
new RequestError(
{
code: 'connector.invalid_id_token',
code: 'connector.social_invalid_id_token',
status: 401,
},
{ message }

View file

@ -21,77 +21,32 @@ export default function koaConnectorErrorHandler<StateT, ContextT>(): Middleware
const errorMessage = conditional(result.success && '\n' + result.data.errorDescription);
switch (code) {
case ConnectorErrorCodes.InvalidMetadata:
case ConnectorErrorCodes.InvalidConfigGuard:
case ConnectorErrorCodes.InsufficientRequestParameters:
throw new RequestError(
{
code: 'connector.insufficient_request_parameters',
status: 400,
},
data
);
case ConnectorErrorCodes.InvalidConfig:
throw new RequestError(
{
code: 'connector.invalid_config',
status: 400,
},
data
);
case ConnectorErrorCodes.InvalidResponse:
throw new RequestError(
{
code: 'connector.invalid_response',
status: 400,
},
data
);
throw new RequestError({ code: `connector.${code}`, status: 400 }, data);
case ConnectorErrorCodes.SocialAuthCodeInvalid:
case ConnectorErrorCodes.SocialAccessTokenInvalid:
case ConnectorErrorCodes.SocialIdTokenInvalid:
case ConnectorErrorCodes.AuthorizationFailed:
throw new RequestError({ code: `connector.${code}`, status: 401 }, data);
case ConnectorErrorCodes.TemplateNotFound:
throw new RequestError(
{
code: 'connector.template_not_found',
code: `connector.${code}`,
status: 500,
},
data
);
case ConnectorErrorCodes.NotImplemented:
throw new RequestError({ code: 'connector.not_implemented', status: 501 }, data);
case ConnectorErrorCodes.SocialAuthCodeInvalid:
throw new RequestError(
{
code: 'connector.oauth_code_invalid',
status: 401,
},
data
);
case ConnectorErrorCodes.SocialAccessTokenInvalid:
throw new RequestError(
{
code: 'connector.invalid_access_token',
status: 401,
},
data
);
case ConnectorErrorCodes.SocialIdTokenInvalid:
throw new RequestError(
{
code: 'connector.invalid_id_token',
status: 401,
},
data
);
case ConnectorErrorCodes.AuthorizationFailed:
throw new RequestError(
{
code: 'connector.authorization_failed',
status: 401,
},
data
);
throw new RequestError({ code: `connector.${code}`, status: 501 }, data);
default:
throw new RequestError(
{
code: 'connector.general',
code: `connector.${code}`,
status: 500,
errorDescription: errorMessage,
},

View file

@ -62,16 +62,18 @@ const errors = {
general: 'An unexpected error occurred in connector.{{errorDescription}}',
not_found: 'Cannot find any available connector for type: {{type}}.',
not_enabled: 'The connector is not enabled.',
invalid_metadata: "The connector's metadata is invalid.",
invalid_config_guard: "The connector's config guard is invalid.",
insufficient_request_parameters: 'The request might miss some input parameters.',
invalid_config: "The connector's config is invalid.",
invalid_response: "The connector's response is invalid.",
template_not_found: 'Unable to find correct template in connector config.',
not_implemented: '{{method}}: has not been implemented yet.',
invalid_access_token: "The connector's access token is invalid.",
social_invalid_access_token: "The connector's access token is invalid.",
invalid_auth_code: "The connector's auth code is invalid.",
invalid_id_token: "The connector's id token is invalid.",
social_invalid_id_token: "The connector's id token is invalid.",
authorization_failed: "The user's authorization process is unsuccessful.",
oauth_code_invalid: 'Unable to get access token, please check authorization code.',
social_auth_code_invalid: 'Unable to get access token, please check authorization code.',
more_than_one_sms: 'The number of SMS connectors is larger then 1.',
more_than_one_email: 'The number of Email connectors is larger then 1.',
db_connector_type_mismatch: 'There is a connector in the DB that does not match the type.',

View file

@ -67,16 +67,18 @@ const errors = {
general: "Une erreur inattendue s'est produite dans le connecteur. {{errorDescription}}",
not_found: 'Impossible de trouver un connecteur disponible pour le type : {{type}}.',
not_enabled: "Le connecteur n'est pas activé.",
invalid_metadata: "The connector's metadata is invalid.", // UNTRANSLATED
invalid_config_guard: "The connector's config guard is invalid.", // UNTRANSLATED
insufficient_request_parameters: 'Certains paramètres peuvent manquer dans la requête.',
invalid_config: "La configuration du connecteur n'est pas valide.",
invalid_response: "La réponse du connecteur n'est pas valide.",
template_not_found: 'Impossible de trouver le bon modèle dans la configuration du connecteur.',
not_implemented: "{{method}} : n'a pas encore été mis en œuvre.",
invalid_access_token: "Le jeton d'accès du connecteur n'est pas valide.",
social_invalid_access_token: "Le jeton d'accès du connecteur n'est pas valide.",
invalid_auth_code: "Le code d'authentification du connecteur n'est pas valide.",
invalid_id_token: "Le jeton d'identification du connecteur n'est pas valide.",
social_invalid_id_token: "Le jeton d'identification du connecteur n'est pas valide.",
authorization_failed: "Le processus d'autorisation de l'utilisateur n'a pas abouti.",
oauth_code_invalid:
social_auth_code_invalid:
"Impossible d'obtenir le jeton d'accès, veuillez vérifier le code d'autorisation.",
more_than_one_sms: 'Le nombre de connecteurs SMS est supérieur à 1.',
more_than_one_email: 'Le nombre de connecteurs Email est supérieur à 1.',

View file

@ -61,16 +61,18 @@ const errors = {
general: '연동 중에 알 수 없는 오류가 발생했어요. {{errorDescription}}',
not_found: '{{type}} 값을 가진 연동 종류를 찾을 수 없어요.',
not_enabled: '연동이 활성화 되지 않았어요.',
invalid_metadata: "The connector's metadata is invalid.", // UNTRANSLATED
invalid_config_guard: "The connector's config guard is invalid.", // UNTRANSLATED
insufficient_request_parameters: '요청 데이터에서 일부 정보가 없어요.',
invalid_config: '연동 설정이 유효하지 않아요.',
invalid_response: '연동 응답이 유효하지 않아요.',
template_not_found: '연동 예제 설정을 찾을 수 없어요.',
not_implemented: '{{method}}은 아직 구현되지 않았어요.',
invalid_access_token: '연동 서비스의 Access 토큰이 유효하지 않아요.',
social_invalid_access_token: '연동 서비스의 Access 토큰이 유효하지 않아요.',
invalid_auth_code: '연동 서비스의 Auth 코드가 유효하지 않아요.',
invalid_id_token: '연동 서비스의 ID 토큰이 유효하지 않아요.',
social_invalid_id_token: '연동 서비스의 ID 토큰이 유효하지 않아요.',
authorization_failed: '사용자의 인증 과정이 성공적으로 마무리되지 않았어요.',
oauth_code_invalid: 'Access 토큰을 가져올 수 없어요. Authorization 코드를 확인해주세요.',
social_auth_code_invalid: 'Access 토큰을 가져올 수 없어요. Authorization 코드를 확인해주세요.',
more_than_one_sms: '연동된 SMS 서비스가 1개 이상이여야 해요.',
more_than_one_email: '연동된 이메일 서비스가 1개 이상이여야 해요.',
db_connector_type_mismatch: '종류가 일치하지 않은 연동 서비스가 DB에 존재해요.',

View file

@ -63,16 +63,18 @@ const errors = {
general: 'Bağlayıcıda beklenmeyen bir hata oldu.{{errorDescription}}',
not_found: '{{type}} tipi icin uygun bağlayıcı bulunamadı.',
not_enabled: 'Bağlayıcı etkin değil.',
invalid_metadata: "The connector's metadata is invalid.", // UNTRANSLATED
invalid_config_guard: "The connector's config guard is invalid.", // UNTRANSLATED
insufficient_request_parameters: 'İstek, bazı input parametrelerini atlayabilir.',
invalid_config: 'Bağlayıcının ayarları geçersiz.',
invalid_response: 'Bağlayıcının yanıtı geçersiz.',
template_not_found: 'Bağlayıcı yapılandırmasında doğru şablon bulunamıyor.',
not_implemented: '{{method}}: henüz uygulanmadı.',
invalid_access_token: 'Bağlayıcının erişim tokenı geçersiz.',
social_invalid_access_token: 'Bağlayıcının erişim tokenı geçersiz.',
invalid_auth_code: 'Bağlayıcının yetki kodu geçersiz.',
invalid_id_token: 'Bağlayıcının idsi geçersiz.',
social_invalid_id_token: 'Bağlayıcının idsi geçersiz.',
authorization_failed: 'Kullanıcının yetkilendirme işlemi başarısız oldu.',
oauth_code_invalid: 'Erişim tokenı alınamıyor, lütfen yetkilendirme kodunu kontrol edin.',
social_auth_code_invalid: 'Erişim tokenı alınamıyor, lütfen yetkilendirme kodunu kontrol edin.',
more_than_one_sms: 'SMS bağlayıcılarının sayısı 1den fazla.',
more_than_one_email: 'E-posta adresi bağlayıcılarının sayısı 1den fazla.',
db_connector_type_mismatch: 'Dbde türle eşleşmeyen bir bağlayıcı var.',

View file

@ -61,16 +61,18 @@ const errors = {
general: '连接器发生未知错误{{errorDescription}}',
not_found: '找不到可用的 {{type}} 类型的连接器',
not_enabled: '连接器尚未启用',
invalid_metadata: '连接器 metadata 参数错误',
invalid_config_guard: '连接器配置 guard 错误',
insufficient_request_parameters: '请求参数缺失',
invalid_config: '连接器配置错误',
invalid_response: '连接器错误响应',
template_not_found: '无法从连接器配置中找到对应的模板',
not_implemented: '方法 {{method}} 尚未实现',
invalid_access_token: '当前连接器的 access_token 无效',
social_invalid_access_token: '当前连接器的 access_token 无效',
invalid_auth_code: '当前连接器的授权码无效',
invalid_id_token: '当前连接器的 id_token 无效',
social_invalid_id_token: '当前连接器的 id_token 无效',
authorization_failed: '用户授权流程失败',
oauth_code_invalid: '无法获取 access_token请检查授权 code 是否有效',
social_auth_code_invalid: '无法获取 access_token请检查授权 code 是否有效',
more_than_one_sms: '同时存在超过 1 个短信连接器',
more_than_one_email: '同时存在超过 1 个邮件连接器',
db_connector_type_mismatch: '数据库中存在一个类型不匹配的连接。',