Improving error throwing and handling in pusher/admin/front

This commit is contained in:
David Négrier 2021-03-31 15:48:25 +02:00
parent 9bfd07f00c
commit cd7a332b4c
4 changed files with 21 additions and 9 deletions

View file

@ -24,7 +24,7 @@ class AdminApi {
async fetchMapDetails(organizationSlug: string, worldSlug: string, roomSlug: string|undefined): Promise<AdminApiData> {
if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!');
return Promise.reject(new Error('No admin backoffice set!'));
}
const params: { organizationSlug: string, worldSlug: string, roomSlug?: string } = {

View file

@ -69,7 +69,7 @@ class ConnectionManager {
return Promise.resolve(new Room(roomId));
}
return Promise.reject('Invalid URL');
return Promise.reject(new Error('Invalid URL'));
}
private async verifyToken(token: string): Promise<void> {

View file

@ -13,8 +13,20 @@ export class BaseController {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected errorToResponse(e: any, res: HttpResponse): void {
console.error(e.message || "An error happened.", e?.config.url);
console.error(e.stack || 'no stack defined.');
if (e && e.message) {
let url = e?.config?.url;
if (url !== undefined) {
url = ' for URL: '+url;
} else {
url = '';
}
console.error('ERROR: '+e.message+url);
} else if (typeof(e) === 'string') {
console.error(e);
}
if (e.stack) {
console.error(e.stack);
}
if (e.response) {
res.writeStatus(e.response.status+" "+e.response.statusText);
this.addCorsHeaders(res);

View file

@ -37,7 +37,7 @@ class AdminApi {
async fetchMapDetails(organizationSlug: string, worldSlug: string, roomSlug: string|undefined): Promise<AdminApiData> {
if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!');
return Promise.reject(new Error('No admin backoffice set!'));
}
const params: { organizationSlug: string, worldSlug: string, roomSlug?: string } = {
@ -60,7 +60,7 @@ class AdminApi {
async fetchMemberDataByUuid(uuid: string, roomId: string): Promise<FetchMemberDataByUuidResponse> {
if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!');
return Promise.reject(new Error('No admin backoffice set!'));
}
const res = await Axios.get(ADMIN_API_URL+'/api/room/access',
{ params: {uuid, roomId}, headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }
@ -70,7 +70,7 @@ class AdminApi {
async fetchMemberDataByToken(organizationMemberToken: string): Promise<AdminApiData> {
if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!');
return Promise.reject(new Error('No admin backoffice set!'));
}
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
const res = await Axios.get(ADMIN_API_URL+'/api/login-url/'+organizationMemberToken,
@ -81,7 +81,7 @@ class AdminApi {
async fetchCheckUserByToken(organizationMemberToken: string): Promise<AdminApiData> {
if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!');
return Promise.reject(new Error('No admin backoffice set!'));
}
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
const res = await Axios.get(ADMIN_API_URL+'/api/check-user/'+organizationMemberToken,
@ -104,7 +104,7 @@ class AdminApi {
async verifyBanUser(organizationMemberToken: string, ipAddress: string, organization: string, world: string): Promise<AdminBannedData> {
if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!');
return Promise.reject(new Error('No admin backoffice set!'));
}
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
return Axios.get(ADMIN_API_URL + '/api/check-moderate-user/'+organization+'/'+world+'?ipAddress='+ipAddress+'&token='+organizationMemberToken,