Files
FastGPT/packages/global/test/common/error/utils.test.ts
T
Ryo 289da0f7b0 chore: bump pro submodule for hydration stability (#6808)
* sandbox-sync-agent

* refactor: host pro as submodule

* chore: checkpoint host pro restructure

* refactor workspace test layout and startup init

* chore: update next turbopack setup

* chore: snapshot current work before actions fix

* chore: update pro submodule

* chore: point pro submodule url to upstream https

* fix: Dockerfile

* chore: update pro submodule

* ci: support private pro submodule token and skip fork jobs

* fix(ci): build sdk workspace deps before code-sandbox bundle

* fix(app): exclude vitest configs from production typecheck

* fix(app-image): build sdk packages before next build

* fix(ci): align dockerfiles with workspace sdk build flow

* chore(docker): upgrade node20 docker images to node24

* fix(ci): read admin coverage output path in pro test workflow

* fix(app-image): include next-i18next config and locale assets

* chore: update pro submodule

* chore: do not specify branch for submodule

* chore: remove most ts-nocheck sign

* chore: update pro submodule

* chore: remove sandbox-agent-sync package

* chore: do not modify "pushData" file logic

* fix: health check

* chore: restore dev axios proxy state

* fix: test-fastgpt report workflow

* fix: use valid vitest coverage action inputs
2026-04-27 17:44:12 +08:00

59 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { getErrText, UserError } from '@fastgpt/global/common/error/utils';
import { ERROR_ENUM, ERROR_RESPONSE } from '@fastgpt/global/common/error/errorCode';
describe('getErrText', () => {
it('should return mapped message for error enum', () => {
const result = getErrText(ERROR_ENUM.unAuthorization);
expect(result).toBe(ERROR_RESPONSE[ERROR_ENUM.unAuthorization].message);
});
it('should prefer response.data.message over other fields', () => {
const err = {
response: {
data: {
message: 'primary message',
msg: 'fallback data msg'
},
message: 'response message',
msg: 'response msg'
},
message: 'base message',
msg: 'base msg'
};
expect(getErrText(err)).toBe('primary message');
});
it('should return first axios error message', () => {
const err = {
errors: [{ message: 'first axios error' }, { message: 'second axios error' }]
};
expect(getErrText(err)).toBe('first axios error');
});
it('should fall back to default value', () => {
expect(getErrText(undefined, 'default message')).toBe('default message');
});
it('should mask sensitive text in message', () => {
const err = {
message: 'https://example.com/secret ns-abc-123'
};
expect(getErrText(err)).toBe('https://xxx xxx');
});
});
describe('UserError', () => {
it('should set name to UserError', () => {
const err = new UserError('boom');
expect(err).toBeInstanceOf(Error);
expect(err.name).toBe('UserError');
expect(err.message).toBe('boom');
});
});