-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): mutating request debug mode
- Loading branch information
1 parent
91bd4c1
commit 6303629
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {module, IRequestConfig, IHttpInterceptor, IHttpProvider} from 'angular'; | ||
import {$log, $location} from 'ngimport'; | ||
import {JSON_UTILITY_SERVICE, JsonUtilityService} from 'core/utils/json/json.utility.service'; | ||
import autoBindMethods from 'class-autobind-decorator'; | ||
|
||
@autoBindMethods | ||
export class DebugInterceptor implements IHttpInterceptor { | ||
|
||
constructor(private jsonUtilityService: JsonUtilityService) { 'ngInject'; } | ||
|
||
public request(config: IRequestConfig): IRequestConfig { | ||
try { // This is a great opportunity to break Deck, so be careful. | ||
this.logMutatingRequest(config); | ||
} catch (e) { | ||
$log.warn('Debug interceptor bug: ', e.message); | ||
} | ||
return config; | ||
} | ||
|
||
private logMutatingRequest(config: IRequestConfig): void { | ||
if ($location.url() && | ||
$location.url().includes('debug=true') && | ||
['POST', 'PUT', 'DELETE'].includes(config.method)) { | ||
$log.log(`${config.method}: ${config.url} \n`, this.jsonUtilityService.makeSortedStringFromObject(config.data)); | ||
} | ||
} | ||
} | ||
|
||
export const DEBUG_INTERCEPTOR = 'spinnaker.core.debug.interceptor'; | ||
module(DEBUG_INTERCEPTOR, [JSON_UTILITY_SERVICE]) | ||
.service('debugInterceptor', DebugInterceptor) | ||
.config(($httpProvider: IHttpProvider) => $httpProvider.interceptors.push('debugInterceptor')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {module} from 'angular'; | ||
|
||
import {DEBUG_INTERCEPTOR} from './debug.interceptor'; | ||
|
||
export const INTERCEPTOR_MODULE = 'spinnaker.core.interceptor.module'; | ||
module(INTERCEPTOR_MODULE, [ | ||
DEBUG_INTERCEPTOR, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters