Browse Source

feat(nocodb): insert hook log based on NC_AUTOMATION_LOG_LEVEL

pull/5349/head
Wing-Kam Wong 1 year ago
parent
commit
c850074d73
  1. 98
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts
  2. 3
      packages/nocodb/src/lib/models/HookLog.ts

98
packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

@ -301,14 +301,16 @@ export async function invokeWebhook(
subject: parseBody(notification?.payload?.subject, newData),
html: parseBody(notification?.payload?.body, newData),
});
hookLog = {
...hook,
fk_hook_id: hook.id,
type: notification.type,
payload: JSON.stringify(notification?.payload),
response: JSON.stringify(res),
triggered_by: user?.email,
};
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
hookLog = {
...hook,
fk_hook_id: hook.id,
type: notification.type,
payload: JSON.stringify(notification?.payload),
response: JSON.stringify(res),
triggered_by: user?.email,
};
}
}
break;
case 'URL':
@ -323,25 +325,27 @@ export async function invokeWebhook(
newData
);
hookLog = {
...hook,
fk_hook_id: hook.id,
type: notification.type,
payload: JSON.stringify(notification?.payload),
response: JSON.stringify({
status: res.status,
statusText: res.statusText,
headers: res.headers,
config: {
url: res.config.url,
method: res.config.method,
data: res.config.data,
headers: res.config.headers,
params: res.config.params,
},
}),
triggered_by: user?.email,
};
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
hookLog = {
...hook,
fk_hook_id: hook.id,
type: notification.type,
payload: JSON.stringify(notification?.payload),
response: JSON.stringify({
status: res.status,
statusText: res.statusText,
headers: res.headers,
config: {
url: res.config.url,
method: res.config.method,
data: res.config.data,
headers: res.config.headers,
params: res.config.params,
},
}),
triggered_by: user?.email,
};
}
}
break;
default:
@ -357,29 +361,33 @@ export async function invokeWebhook(
})
);
hookLog = {
...hook,
fk_hook_id: hook.id,
type: notification.type,
payload: JSON.stringify(notification?.payload),
response: JSON.stringify(res),
triggered_by: user?.email,
};
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
hookLog = {
...hook,
fk_hook_id: hook.id,
type: notification.type,
payload: JSON.stringify(notification?.payload),
response: JSON.stringify(res),
triggered_by: user?.email,
};
}
}
break;
}
} catch (e) {
console.log(e);
hookLog = {
...hook,
type: notification.type,
payload: JSON.stringify(notification?.payload),
fk_hook_id: hook.id,
error_code: e.error_code,
error_message: e.message,
error: JSON.stringify(e),
triggered_by: user?.email,
};
if (['ERROR', 'ALL'].includes(process.env.NC_AUTOMATION_LOG_LEVEL)) {
hookLog = {
...hook,
type: notification.type,
payload: JSON.stringify(notification?.payload),
fk_hook_id: hook.id,
error_code: e.error_code,
error_message: e.message,
error: JSON.stringify(e),
triggered_by: user?.email,
};
}
if (throwErrorOnFailure) throw e;
} finally {
if (hookLog) {

3
packages/nocodb/src/lib/models/HookLog.ts

@ -63,6 +63,9 @@ export default class HookLog implements HookLogType {
}
public static async insert(hookLog: Partial<HookLog>, ncMeta = Noco.ncMeta) {
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'OFF') {
return;
}
const insertObj: any = extractProps(hookLog, [
'base_id',
'project_id',

Loading…
Cancel
Save