Created
March 6, 2019 18:10
-
-
Save taosx/dc92e22b6f7f4d986f7ee8388a80b9f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type badStates = | |
| ECONNREFUSED /* database not running, or running on different port */ | |
| SHUTTING_DOWN | |
| STARTING_UP | |
| ERROR(string); | |
let db_state = xs => ( | |
Js.String.includes("ECONNREFUSED", xs), | |
Js.String.includes("is shutting down", xs), | |
Js.String.includes("is starting up", xs), | |
); | |
let stateMatcher: Js.Promise.error => badStates = | |
err => { | |
let errStr = Js.String.make(err); | |
switch (db_state(errStr)) { | |
| (true, false, false) => ECONNREFUSED | |
| (false, true, false) => SHUTTING_DOWN | |
| (false, false, true) => STARTING_UP | |
| (_, _, _) => ERROR(errStr) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment