Skip to content

Instantly share code, notes, and snippets.

@love8587
Created December 19, 2019 08:58
Show Gist options
  • Select an option

  • Save love8587/e9f545f992dac4eff1ef77d341204c2a to your computer and use it in GitHub Desktop.

Select an option

Save love8587/e9f545f992dac4eff1ef77d341204c2a to your computer and use it in GitHub Desktop.
Async / Await > Catch Error stack trace
getSiteMeta: async (ctx: Context, next: Function) => {
try {
const url = ctx.query.url;
const result = await utilsService.getSiteMeta({ url });
return success(ctx, 200, `get site meta`, result.data);
} catch (err) {
err.stack = `${err.stack} ${new Error().stack}`;
throw err;
}
}
getSiteMeta: async (param: { url: string }) => {
if (!param || !param.url) {
throw boom.badRequest(undefined, { param });
}
try {
const result = await NewsConnector.getSiteMeta(param.url);
return respondSuccess(result);
} catch (err) {
err.stack = `${err.stack} ${new Error().stack}`;
throw respondError(err);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment