dify/sdks/nodejs-client/src/errors/dify-error.test.ts
Stephen Zhou a84c2d36a3
style: format with vp fmt (#38803)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-12 15:57:46 +00:00

38 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
APIError,
AuthenticationError,
DifyError,
FileUploadError,
NetworkError,
RateLimitError,
TimeoutError,
ValidationError,
} from './dify-error'
describe('Dify errors', () => {
it('sets base error fields', () => {
const err = new DifyError('base', {
statusCode: 400,
responseBody: { message: 'bad' },
requestId: 'req',
retryAfter: 1,
})
expect(err.name).toBe('DifyError')
expect(err.statusCode).toBe(400)
expect(err.responseBody).toEqual({ message: 'bad' })
expect(err.requestId).toBe('req')
expect(err.retryAfter).toBe(1)
})
it('creates specific error types', () => {
expect(new APIError('api').name).toBe('APIError')
expect(new AuthenticationError('auth').name).toBe('AuthenticationError')
expect(new RateLimitError('rate').name).toBe('RateLimitError')
expect(new ValidationError('val').name).toBe('ValidationError')
expect(new NetworkError('net').name).toBe('NetworkError')
expect(new TimeoutError('timeout').name).toBe('TimeoutError')
expect(new FileUploadError('upload').name).toBe('FileUploadError')
})
})