From 124a6bf295b2cdc9f88ba419772dbdc6ebbca3a7 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Tue, 16 Mar 2021 18:32:26 +0300 Subject: [PATCH] Refactor environment variables. --- src/app/_interceptors/error.interceptor.ts | 11 +++++++---- src/app/_services/auth.service.ts | 8 ++++---- src/environments/environment.prod.ts | 9 +++------ src/environments/environment.ts | 13 +++++-------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/app/_interceptors/error.interceptor.ts b/src/app/_interceptors/error.interceptor.ts index b1f717a..83d64ff 100644 --- a/src/app/_interceptors/error.interceptor.ts +++ b/src/app/_interceptors/error.interceptor.ts @@ -8,6 +8,7 @@ import { import {Observable, throwError} from 'rxjs'; import {catchError} from 'rxjs/operators'; import {ErrorDialogService} from '@app/_services'; +import {environment} from '@src/environments/environment'; @Injectable() export class ErrorInterceptor implements HttpInterceptor { @@ -16,10 +17,12 @@ export class ErrorInterceptor implements HttpInterceptor { intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe(catchError((err: HttpErrorResponse) => { - this.errorDialogService.openDialog({ - message: err.error.message || err.statusText, - status: err.status - }); + if (!environment.production) { + this.errorDialogService.openDialog({ + message: err.error.message || err.statusText || 'Unknown Error', + status: err.status || 0 + }); + } if ([401, 403].indexOf(err.status) !== -1) { location.reload(true); } diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index d0e19fa..4f929f0 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -37,7 +37,7 @@ export class AuthService { getWithToken(): void { const xhr = new XMLHttpRequest(); xhr.responseType = 'text'; - xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); + xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1)); xhr.setRequestHeader('Authorization', 'Bearer ' + this.sessionToken); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('x-cic-automerge', 'none'); @@ -55,7 +55,7 @@ export class AuthService { sendResponse(hobaResponseEncoded): void { const xhr = new XMLHttpRequest(); xhr.responseType = 'text'; - xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); + xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1)); xhr.setRequestHeader('Authorization', 'HOBA ' + hobaResponseEncoded); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('x-cic-automerge', 'none'); @@ -75,7 +75,7 @@ export class AuthService { getChallenge(): void { const xhr = new XMLHttpRequest(); xhr.responseType = 'arraybuffer'; - xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); + xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1)); xhr.onload = (e) => { if (xhr.status === 401) { const authHeader = xhr.getResponseHeader('WWW-Authenticate'); @@ -107,7 +107,7 @@ export class AuthService { async loginResponse(o): Promise { - const r = await signChallenge(o.challenge, o.realm, environment.cicAuthUrl, this.mutableKeyStore); + const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore); this.sendResponse(r); } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 64cc72f..e49a487 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -6,14 +6,11 @@ export const environment = { level: NgxLoggerLevel.OFF, serverLogLevel: NgxLoggerLevel.ERROR, loggingUrl: 'http://localhost:8000', - cicAuthUrl: 'https://meta.dev.grassrootseconomics.net:80', - cicMetaUrl: 'http://localhost:63380', + cicMetaUrl: 'https://meta.grassrootseconomics.net', publicKeysUrl: 'http://localhost:8000/keys.asc', - cicCacheUrl: 'http://localhost:63313', - cicScriptsUrl: 'http://localhost:9999', + cicCacheUrl: 'https://cache.grassrootseconomics.net', web3Provider: 'ws://localhost:63546', - cicUssdUrl: 'http://localhost:63315', - cicEthUrl: 'http://localhost:63314', + cicUssdUrl: 'https://ussd.grassrootseconomics.net', registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8', trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 93867c3..1a5f914 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -8,16 +8,13 @@ export const environment = { production: false, bloxbergChainId: 8996, level: NgxLoggerLevel.TRACE, - serverLogLevel: NgxLoggerLevel.ERROR, + serverLogLevel: NgxLoggerLevel.OFF, loggingUrl: 'http://localhost:8000', - cicAuthUrl: 'https://meta.dev.grassrootseconomics.net:80', - cicMetaUrl: 'http://localhost:63380', + cicMetaUrl: 'https://meta.dev.grassrootseconomics.net', publicKeysUrl: 'http://localhost:8000/keys.asc', - cicCacheUrl: 'http://localhost:63313', - cicScriptsUrl: 'http://localhost:9999', - web3Provider: 'ws://localhost:63546', - cicUssdUrl: 'http://localhost:63315', - cicEthUrl: 'http://localhost:63314', + cicCacheUrl: 'https://cache.dev.grassrootseconomics.net', + web3Provider: 'ws://localhost:8548', + cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net', registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8', trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' };