We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 302fc12 commit 53df668Copy full SHA for 53df668
1 file changed
JavaScript/8-promisify.js
@@ -20,12 +20,25 @@ const main = async () => {
20
const fileName = '8-promisify.js';
21
const data = await read(fileName, 'utf8');
22
console.log(`File "${fileName}" size: ${data.length}`);
23
+
24
+ // Call from try/catch block
25
try {
26
const data = await read('unknown.file', 'utf8');
27
console.log(`File size: ${data.length}`);
28
} catch (error) {
29
console.error(error.message);
30
}
31
32
+ // Set default value in promise.catch block
33
+ const content = await read('unknown.file').catch((error) => {
34
+ console.error(error.message);
35
+ return null;
36
+ });
37
+ // Warning: note that you need additional if-statement
38
+ if (content) {
39
+ console.log({ content });
40
+ console.log(`File size: ${content.size}`);
41
+ }
42
};
43
44
main();
0 commit comments