Look at the code generated by this snippet:
exception NetworkError({status: int, message: string})
type response
exception HttpError({status: int, message: string, response: response})
let isRetriable: exn => bool = error =>
switch error {
| NetworkError(_) => true
| HttpError({status: 502 | 503 | 504}) => true
| _ => false
}
The generated JS uses (error.status - 502 | 0) <= 2 but that is also true for 500, 501, 404, etc.
function isRetriable(error) {
if (error.RE_EXN_ID === NetworkError) {
return true;
} else if (error.RE_EXN_ID === HttpError) {
return (error.status - 502 | 0) <= 2;
} else {
return false;
}
}
Rescript 13.0 (alpha 5), emits the same JS.