Skip to content

Commit fc64ffb

Browse files
committed
cleaner error handling
1 parent 9db4b8e commit fc64ffb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/compass-data-modeling/src/services/open-and-download-diagram.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ export async function getDiagramContentsFromFile(
3434
const reader = new FileReader();
3535
return new Promise((resolve, reject) => {
3636
reader.onload = (event) => {
37-
const content = event.target?.result;
38-
if (typeof content !== 'string') {
39-
return reject(new Error('Invalid file contents'));
40-
}
4137
try {
38+
const content = event.target?.result;
39+
if (typeof content !== 'string') {
40+
throw new Error('Invalid file contents');
41+
}
4242
const parsedContent = JSON.parse(content);
4343

4444
if (
4545
parsedContent.version !== kCurrentVersion ||
4646
parsedContent.type !== kFileTypeDescription
4747
) {
48-
return reject(new Error('Unsupported diagram file format'));
48+
throw new Error('Unsupported diagram file format');
4949
}
5050

5151
const { name, edits } = parsedContent;
5252

5353
if (!name || !edits || typeof edits !== 'string') {
54-
return reject(new Error('Diagram file is missing required fields'));
54+
throw new Error('Diagram file is missing required fields');
5555
}
5656

5757
const parsedEdits = JSON.parse(

0 commit comments

Comments
 (0)