返回 AiToEarn
volcengine.exception.spec.ts
根目录 / project / aitoearn-backend / apps / aitoearn-ai / src / core / ai / libs / volcengine / volcengine.exception.spec.ts
1 import { requestContext } from '@yikart/common'
2 import { VolcengineException } from './volcengine.exception'
3
4 function buildProviderError() {
5 return {
6 isAxiosError: true,
7 message: 'Request failed with status code 400',
8 config: {
9 method: 'post',
10 url: '/api/v3/contents/generations/tasks',
11 },
12 response: {
13 status: 400,
14 data: {
15 error: {
16 code: 'InputImageSensitiveContentDetected.PrivacyInformation',
17 message: 'The request failed because the input image may contain real person. Request id: 021775813653027eff6165463a2ce5f140dae355499e1796de13b',
18 param: '',
19 type: 'BadRequest',
20 },
21 },
22 },
23 }
24 }
25
26 describe('volcengineException', () => {
27 it('should map provider error to zh-cn official message', () => {
28 const error = requestContext.run({ locale: 'zh-CN' }, () =>
29 VolcengineException.buildFromError(
30 buildProviderError(),
31 'POST /api/v3/contents/generations/tasks',
32 ))
33
34 expect(error.message).toBe('输入图片可能包含真人,请您更换后重试。(Request ID: 021775813653027eff6165463a2ce5f140dae355499e1796de13b)')
35 expect(error.httpStatus).toBe(400)
36 expect(error.providerCode).toBe('InputImageSensitiveContentDetected.PrivacyInformation')
37 expect(error.providerType).toBe('BadRequest')
38 expect(error.providerParam).toBe('')
39 expect(error.requestId).toBe('021775813653027eff6165463a2ce5f140dae355499e1796de13b')
40 expect(error.getResponse()).toEqual({
41 code: 400,
42 message: '输入图片可能包含真人,请您更换后重试。(Request ID: 021775813653027eff6165463a2ce5f140dae355499e1796de13b)',
43 data: {
44 operation: 'POST /api/v3/contents/generations/tasks',
45 providerCode: 'InputImageSensitiveContentDetected.PrivacyInformation',
46 providerMessage: 'The request failed because the input image may contain real person. Request id: 021775813653027eff6165463a2ce5f140dae355499e1796de13b',
47 providerType: 'BadRequest',
48 providerParam: '',
49 requestId: '021775813653027eff6165463a2ce5f140dae355499e1796de13b',
50 },
51 })
52 })
53
54 it('should map provider error to en-us official message', () => {
55 const error = requestContext.run({ locale: 'en-US' }, () =>
56 VolcengineException.buildFromError(
57 buildProviderError(),
58 'POST /api/v3/contents/generations/tasks',
59 ))
60
61 expect(error.message).toBe('The request failed because the input image may contain real person. (Request ID: 021775813653027eff6165463a2ce5f140dae355499e1796de13b)')
62 })
63 })
64
64 lines TYPESCRIPT