feat: extract code from WS error

This commit is contained in:
Adhiraj Singh
2022-06-16 20:43:51 +05:30
parent bd6be89d57
commit 23acc1fb39
2 changed files with 21 additions and 2 deletions

View File

@@ -328,4 +328,18 @@ export const getCallStatusFromNode = ({ tag, attrs }: BinaryNode) => {
}
return status
}
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: '
export const getCodeFromWSError = (error: Error) => {
let statusCode = 500
if(error.message.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
const code = +error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length)
if(!Number.isNaN(code) && code >= 400) {
statusCode = code
}
}
return statusCode
}