-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1206 from ably/connection-errors-no-early-init
refactor: avoid early initialisation of connection errors
- Loading branch information
Showing
5 changed files
with
61 additions
and
50 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
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 |
---|---|---|
@@ -1,54 +1,65 @@ | ||
import ErrorInfo from '../types/errorinfo'; | ||
|
||
const ConnectionErrorCodes = { | ||
DISCONNECTED: 80003, | ||
SUSPENDED: 80002, | ||
FAILED: 80000, | ||
CLOSING: 80017, | ||
CLOSED: 80017, | ||
UNKNOWN_CONNECTION_ERR: 50002, | ||
UNKNOWN_CHANNEL_ERR: 50001, | ||
}; | ||
|
||
const ConnectionErrors = { | ||
disconnected: ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: 80003, | ||
message: 'Connection to server temporarily unavailable', | ||
}), | ||
suspended: ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: 80002, | ||
message: 'Connection to server unavailable', | ||
}), | ||
failed: ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: 80000, | ||
message: 'Connection failed or disconnected by server', | ||
}), | ||
closing: ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: 80017, | ||
message: 'Connection closing', | ||
}), | ||
closed: ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: 80017, | ||
message: 'Connection closed', | ||
}), | ||
unknownConnectionErr: ErrorInfo.fromValues({ | ||
statusCode: 500, | ||
code: 50002, | ||
message: 'Internal connection error', | ||
}), | ||
unknownChannelErr: ErrorInfo.fromValues({ | ||
statusCode: 500, | ||
code: 50001, | ||
message: 'Internal channel error', | ||
}), | ||
disconnected: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: ConnectionErrorCodes.DISCONNECTED, | ||
message: 'Connection to server temporarily unavailable', | ||
}), | ||
suspended: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: ConnectionErrorCodes.SUSPENDED, | ||
message: 'Connection to server unavailable', | ||
}), | ||
failed: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: ConnectionErrorCodes.FAILED, | ||
message: 'Connection failed or disconnected by server', | ||
}), | ||
closing: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: ConnectionErrorCodes.CLOSING, | ||
message: 'Connection closing', | ||
}), | ||
closed: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 400, | ||
code: ConnectionErrorCodes.CLOSED, | ||
message: 'Connection closed', | ||
}), | ||
unknownConnectionErr: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 500, | ||
code: ConnectionErrorCodes.UNKNOWN_CONNECTION_ERR, | ||
message: 'Internal connection error', | ||
}), | ||
unknownChannelErr: () => | ||
ErrorInfo.fromValues({ | ||
statusCode: 500, | ||
code: ConnectionErrorCodes.UNKNOWN_CONNECTION_ERR, | ||
message: 'Internal channel error', | ||
}), | ||
}; | ||
|
||
export function isRetriable(err: ErrorInfo) { | ||
if (!err.statusCode || !err.code || err.statusCode >= 500) { | ||
return true; | ||
} | ||
let retriable = false; | ||
Object.values(ConnectionErrors).forEach(function (connErr) { | ||
if (connErr.code && connErr.code == err.code) { | ||
retriable = true; | ||
} | ||
}); | ||
return retriable; | ||
return Object.values(ConnectionErrorCodes).includes(err.code); | ||
} | ||
|
||
export default ConnectionErrors; |
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