Add thrift method error handling (#31)

This commit is contained in:
Ildar Galeev 2022-12-23 15:55:56 +03:00 committed by GitHub
parent 1de9830342
commit 760847927d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,39 +46,52 @@ export const codegenClientReducer =
[name]: async (...objectArgs: object[]): Promise<object> => {
const thriftMethod = (): Promise<object> =>
new Promise(async (resolve, reject) => {
const thriftArgs = createArgInstances(
objectArgs,
args,
meta,
namespace,
context
);
/**
* Connection errors come with HTTP errors (!= 200) and should be handled with errors from the service.
* You need to have 1 free connection per request. Otherwise, the error cannot be caught or identified.
*/
const connection = connectClient(
location.hostname,
location.port,
path,
service,
{
headers,
deadlineConfig,
},
(err) => {
reject(err);
try {
const thriftArgs = createArgInstances(
objectArgs,
args,
meta,
namespace,
context
);
/**
* Connection errors come with HTTP errors (!= 200) and should be handled with errors from the service.
* You need to have 1 free connection per request. Otherwise, the error cannot be caught or identified.
*/
const connection = connectClient(
location.hostname,
location.port,
path,
service,
{
headers,
deadlineConfig,
},
(err) => {
reject(err);
}
) as any;
const thriftResponse = await callThriftService(
connection,
name,
thriftArgs
);
const response = thriftInstanceToObject(
meta,
namespace,
type,
thriftResponse
);
if (logging) {
console.info(`🟢 ${namespace}.${serviceName}.${name}`, {
args: objectArgs,
response,
});
}
) as any;
const thriftResponse = await callThriftService(connection, name, thriftArgs);
const response = thriftInstanceToObject(meta, namespace, type, thriftResponse);
if (logging) {
console.info(`🟢 ${namespace}.${serviceName}.${name}`, {
args: objectArgs,
response,
});
resolve(response);
} catch (ex) {
reject(ex);
}
resolve(response);
});
try {
return await thriftMethod();