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);
|
}
|
}
|
}
|