Hong-Phuc Bui
2025-01-16 2889de7f0c2d587a17fbd322af57c29e84238620
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const NETWORK_ERROR = "[network-error]";
const USER_INPUT_ERROR = "[user-error]";
 
function demoErrorWithSpecMessage(type) {
    try {
        if (type===1) {
            throw new Error(`${NETWORK_ERROR} server unreachable`);
        } else if (type === 2) {
            throw new Error(`${USER_INPUT_ERROR} input is not a number`);
        }
    } catch(e) {
        const msg = e.message;
        if(msg.startsWith(NETWORK_ERROR)) {
            // TODO: write error message to id = "server eerror"
        } else if(msg.startsWith(USER_INPUT_ERROR)) {
            // TODO: mark the input field with red border
        } else {
            throw new Error(msg);
        }
    }
}