Files
mattermost-mobile/app/client/rest/error.ts
Daniel Espino García 86658edc30 Refactor errors around the app (#7306)
* Refactor errors around the app

* Fix recursive function

* Fix tests
2023-05-03 13:08:55 +02:00

27 lines
964 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {cleanUrlForLogging} from '@utils/url';
export default class ClientError extends Error {
url: string;
intl?: ClientErrorIntl;
server_error_id?: string;
status_code?: number;
details?: unknown;
constructor(baseUrl: string, data: ClientErrorProps) {
super(data.message + ': ' + cleanUrlForLogging(baseUrl, data.url));
this.message = data.message;
this.url = data.url;
this.intl = data.intl;
this.server_error_id = data.server_error_id;
this.status_code = data.status_code;
this.details = data.details;
// Ensure message is treated as a property of this class when object spreading. Without this,
// copying the object by using `{...error}` would not include the message.
Object.defineProperty(this, 'message', {enumerable: true});
}
}