Skip to content

Instantly share code, notes, and snippets.

@taosx
Created March 6, 2019 18:10
Show Gist options
  • Save taosx/dc92e22b6f7f4d986f7ee8388a80b9f1 to your computer and use it in GitHub Desktop.
Save taosx/dc92e22b6f7f4d986f7ee8388a80b9f1 to your computer and use it in GitHub Desktop.
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