-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathgrpc_error_details.js
More file actions
49 lines (39 loc) · 1.53 KB
/
grpc_error_details.js
File metadata and controls
49 lines (39 loc) · 1.53 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
import grpc from 'k6/net/grpc';
import { check } from 'k6';
const client = new grpc.Client();
client.load(['definitions'], 'hello.proto');
export default () => {
client.connect('localhost:10000', {
plaintext: true
});
const data = { greeting: 'Bert' };
const response = client.invoke('hello.HelloService/SayHello', data);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
// If there's an error with details, log them
if (response.error && response.error.details) {
console.log('Error details:', JSON.stringify(response.error.details, null, 2));
response.error.details.forEach((detail, index) => {
console.log(`Detail ${index} type:`, detail['@type']);
// Example: Check for ErrorInfo
if (detail['@type'] && detail['@type'].includes('ErrorInfo')) {
console.log(' Reason:', detail.reason);
console.log(' Domain:', detail.domain);
console.log(' Metadata:', JSON.stringify(detail.metadata));
}
// Example: Check for RetryInfo
if (detail['@type'] && detail['@type'].includes('RetryInfo')) {
console.log(' Retry delay:', detail.retryDelay);
}
// Example: Check for BadRequest
if (detail['@type'] && detail['@type'].includes('BadRequest')) {
console.log(' Field violations:');
detail.fieldViolations.forEach((violation) => {
console.log(` Field: ${violation.field}, Description: ${violation.description}`);
});
}
});
}
client.close();
};