2021-07-28 21:37:09 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../logging/log';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { HTTPError } from './Errors';
|
2021-09-17 18:27:53 +00:00
|
|
|
|
2021-07-28 21:37:09 +00:00
|
|
|
export async function handleStatusCode(status: number): Promise<void> {
|
|
|
|
if (status === 499) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error('Got 499 from Signal Server. Build is expired.');
|
2021-07-28 21:37:09 +00:00
|
|
|
await window.storage.put('remoteBuildExpiration', Date.now());
|
|
|
|
window.reduxActions.expiration.hydrateExpirationStatus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 00:58:03 +00:00
|
|
|
export function translateError(error: HTTPError): HTTPError | undefined {
|
2021-07-28 21:37:09 +00:00
|
|
|
const { code } = error;
|
|
|
|
if (code === 200) {
|
|
|
|
// Happens sometimes when we get no response. Might be nice to get 204 instead.
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
let message: string;
|
|
|
|
switch (code) {
|
|
|
|
case -1:
|
|
|
|
message =
|
|
|
|
'Failed to connect to the server, please check your network connection.';
|
|
|
|
break;
|
|
|
|
case 413:
|
2022-02-25 00:26:58 +00:00
|
|
|
case 429:
|
2021-07-28 21:37:09 +00:00
|
|
|
message = 'Rate limit exceeded, please try again later.';
|
|
|
|
break;
|
|
|
|
case 403:
|
|
|
|
message = 'Invalid code, please try again.';
|
|
|
|
break;
|
|
|
|
case 417:
|
|
|
|
message = 'Number already registered.';
|
|
|
|
break;
|
|
|
|
case 401:
|
|
|
|
message =
|
|
|
|
'Invalid authentication, most likely someone re-registered and invalidated our registration.';
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
message = 'Number is not registered.';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
message = 'The server rejected our query, please file a bug report.';
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
error.message = `${message} (original: ${error.message})`;
|
|
|
|
return error;
|
|
|
|
}
|