-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Show a more user friendly error message if initial Db connection…
… times out (#10682)
- Loading branch information
Showing
5 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
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
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
14 changes: 14 additions & 0 deletions
14
packages/workflow/src/errors/db-connection-timeout-error.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApplicationError } from './application.error'; | ||
|
||
export type DbConnectionTimeoutErrorOpts = { | ||
configuredTimeoutInMs: number; | ||
cause: Error; | ||
}; | ||
|
||
export class DbConnectionTimeoutError extends ApplicationError { | ||
constructor(opts: DbConnectionTimeoutErrorOpts) { | ||
const numberFormat = Intl.NumberFormat(); | ||
const errorMessage = `Could not establish database connection within the configured timeout of ${numberFormat.format(opts.configuredTimeoutInMs)} ms. Please ensure the database is configured correctly and the server is reachable. You can increase the timeout by setting the 'DB_POSTGRESDB_CONNECTION_TIMEOUT' environment variable.`; | ||
super(errorMessage, { cause: opts.cause }); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** Ensures `error` is an `Error */ | ||
export function ensureError(error: unknown): Error { | ||
return error instanceof Error | ||
? error | ||
: new Error('Error that was not an instance of Error was thrown', { | ||
// We should never throw anything except something that derives from Error | ||
cause: error, | ||
}); | ||
} |
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