-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-error-handling.ts
More file actions
68 lines (56 loc) Β· 2.52 KB
/
Copy pathtest-error-handling.ts
File metadata and controls
68 lines (56 loc) Β· 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Test file to verify error handling functionality
* This can be run to test that error handling works correctly
*/
import { handleVercelError, VercelError } from './src/utils/vercel-error-handler';
// Test various Vercel error scenarios
const testVercelErrors = () => {
console.log('Testing Vercel Error Handling...\n');
// Test 1: 404 error
const error404 = { code: 'NOT_FOUND', statusCode: 404, name: 'Not Found', message: 'Page not found' };
console.log('Test 1 - 404 Error:', handleVercelError(error404)); // Should return '404'
// Test 2: 500 error
const error500 = { code: 'INTERNAL_ERROR', statusCode: 500, name: 'Internal Error', message: 'Server error' };
console.log('Test 2 - 500 Error:', handleVercelError(error500)); // Should return 'internal-error'
// Test 3: Deployment Blocked
const deploymentBlocked: VercelError = {
code: 'DEPLOYMENT_BLOCKED',
statusCode: 403,
name: 'Deployment Blocked',
message: 'This deployment has been blocked'
};
console.log('Test 3 - Deployment Blocked:', handleVercelError(deploymentBlocked)); // Should return 'deployment-blocked'
// Test 4: Function Timeout
const functionTimeout: VercelError = {
code: 'FUNCTION_INVOCATION_TIMEOUT',
statusCode: 504,
name: 'Function Timeout',
message: 'Function took too long'
};
console.log('Test 4 - Function Timeout:', handleVercelError(functionTimeout)); // Should return 'function-timeout'
// Test 5: DNS Error
const dnsError: VercelError = {
code: 'DNS_HOSTNAME_NOT_FOUND',
statusCode: 502,
name: 'DNS Error',
message: 'Hostname not found'
};
console.log('Test 5 - DNS Error:', handleVercelError(dnsError)); // Should return 'dns-error'
// Test 6: Edge Function Error
const edgeFunctionError: VercelError = {
code: 'EDGE_FUNCTION_INVOCATION_FAILED',
statusCode: 500,
name: 'Edge Function Error',
message: 'Edge function failed'
};
console.log('Test 6 - Edge Function Error:', handleVercelError(edgeFunctionError)); // Should return 'edge-function-error'
// Test 7: Network Error (client side)
const networkError = new Error('Network request failed');
console.log('Test 7 - Network Error:', handleVercelError(networkError)); // Should return 'network'
// Test 8: Generic Error
const genericError = new Error('Something went wrong');
console.log('Test 8 - Generic Error:', handleVercelError(genericError)); // Should return 'generic'
console.log('\nAll tests completed!');
};
// Run the tests
testVercelErrors();