Show challenge when requested by server

This commit is contained in:
Fedor Indutny 2021-05-05 17:09:29 -07:00 committed by GitHub
parent 03c68da17d
commit 986d8a66bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 1986 additions and 128 deletions

View file

@ -4,6 +4,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable max-classes-per-file */
import { parseRetryAfter } from '../util/parseRetryAfter';
function appendStack(newError: Error, originalError: Error) {
// eslint-disable-next-line no-param-reassign
newError.stack += `\nOriginal stack:\n${originalError.stack}`;
@ -104,6 +106,37 @@ export class SendMessageNetworkError extends ReplayableError {
}
}
export type SendMessageChallengeData = {
readonly token?: string;
readonly options?: ReadonlyArray<string>;
};
export class SendMessageChallengeError extends ReplayableError {
public identifier: string;
public readonly data: SendMessageChallengeData | undefined;
public readonly retryAfter: number;
constructor(identifier: string, httpError: Error) {
super({
name: 'SendMessageChallengeError',
message: httpError.message,
});
[this.identifier] = identifier.split('.');
this.code = httpError.code;
this.data = httpError.response;
const headers = httpError.responseHeaders || {};
this.retryAfter =
Date.now() + parseRetryAfter(headers['retry-after'].toString());
appendStack(this, httpError);
}
}
export class SignedPreKeyRotationError extends ReplayableError {
constructor() {
super({