Skip to content

Commit

Permalink
feat(rediagram): add error handling on runnning code #133
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiazya committed Nov 30, 2020
1 parent 9dd2fc8 commit 9e4611f
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions packages/rediagram/src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export async function PNG(
element: ReactElement,
{ name, dir, _caller = caller() }: InternalRenderOption = {},
): Promise<void> {
const p = path.parse(_caller);
await Rediagram.render(element, {
format: 'png',
name: name ?? p.name,
dir: dir ?? Rediagram.config.output.dir ?? p.dir,
});
try {
const p = path.parse(_caller);
await Rediagram.render(element, {
format: 'png',
name: name ?? p.name,
dir: dir ?? Rediagram.config.output.dir ?? p.dir,
});
} catch (err) {
Rediagram.logger.error(err);
}
}

/**
Expand All @@ -47,12 +51,16 @@ export async function SVG(
element: ReactElement,
{ name, dir, _caller = caller() }: InternalRenderOption = {},
): Promise<void> {
const p = path.parse(_caller);
await Rediagram.render(element, {
format: 'svg',
name: name ?? p.name,
dir: dir ?? Rediagram.config.output.dir ?? p.dir,
});
try {
const p = path.parse(_caller);
await Rediagram.render(element, {
format: 'svg',
name: name ?? p.name,
dir: dir ?? Rediagram.config.output.dir ?? p.dir,
});
} catch (err) {
Rediagram.logger.error(err);
}
}

/**
Expand All @@ -63,10 +71,14 @@ export async function PDF(
element: ReactElement,
{ name, dir, _caller = caller() }: InternalRenderOption = {},
): Promise<void> {
const p = path.parse(_caller);
await Rediagram.render(element, {
format: 'pdf',
name: name ?? p.name,
dir: dir ?? Rediagram.config.output.dir ?? p.dir,
});
try {
const p = path.parse(_caller);
await Rediagram.render(element, {
format: 'pdf',
name: name ?? p.name,
dir: dir ?? Rediagram.config.output.dir ?? p.dir,
});
} catch (err) {
Rediagram.logger.error(err);
}
}

0 comments on commit 9e4611f

Please sign in to comment.