mirror of
https://github.com/valitydev/frontend-thrift-codegen.git
synced 2024-11-06 02:15:17 +00:00
Add thrift method error handling (#31)
This commit is contained in:
parent
1de9830342
commit
760847927d
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user