Skip to main content
Glama
deepsource-generic-errors.test.ts2.53 kB
/** * @vitest-environment node */ import { expect } from 'vitest'; import { DeepSourceClient } from '../deepsource.js'; describe('DeepSourceClient generic error handling', () => { // We need to access private static methods for testing // @ts-expect-error - Accessing private static method for testing const handleGenericError = DeepSourceClient['handleGenericError']; describe('handleGenericError method', () => { it('should handle Error objects correctly', () => { const error = new Error('Test error message'); try { handleGenericError(error); expect(true).toBe(false); // This will fail if the code reaches here } catch (thrownError) { expect(thrownError).toBeInstanceOf(Error); expect(thrownError.message).toBe('DeepSource API error: Test error message'); } }); it('should handle non-Error objects correctly', () => { const nonErrorObject = { foo: 'bar' }; try { handleGenericError(nonErrorObject); expect(true).toBe(false); // This will fail if the code reaches here } catch (thrownError) { expect(thrownError).toBeInstanceOf(Error); expect(thrownError.message).toBe( 'Unknown error occurred while communicating with DeepSource API' ); } }); it('should handle string errors correctly', () => { const stringError = 'String error'; try { handleGenericError(stringError); expect(true).toBe(false); // This will fail if the code reaches here } catch (thrownError) { expect(thrownError).toBeInstanceOf(Error); expect(thrownError.message).toBe( 'Unknown error occurred while communicating with DeepSource API' ); } }); it('should handle null/undefined errors correctly', () => { try { handleGenericError(null); expect(true).toBe(false); // This will fail if the code reaches here } catch (thrownError) { expect(thrownError).toBeInstanceOf(Error); expect(thrownError.message).toBe( 'Unknown error occurred while communicating with DeepSource API' ); } try { handleGenericError(undefined); expect(true).toBe(false); // This will fail if the code reaches here } catch (thrownError) { expect(thrownError).toBeInstanceOf(Error); expect(thrownError.message).toBe( 'Unknown error occurred while communicating with DeepSource API' ); } }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sapientpants/deepsource-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server