This file contains hidden or 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
| // promise function 1 | |
| function p1(a) { | |
| console.log('p1', a); | |
| return new Promise((resolve, reject) => { | |
| resolve(a * 1); | |
| }); | |
| } | |
| // promise function 2 | |
| function p2(a) { |
This file contains hidden or 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
| <form action="http://bank.com/transfer.do" method="POST"> | |
| <input type="hidden" name="acct" value="ATTACKER_ACCOUNT"/> | |
| <input type="hidden" name="amount" value="100000"/> | |
| <input type="submit" value="View my pictures"/> | |
| </form> |
This file contains hidden or 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
| import { ErrorHandler, Injectable} from '@angular/core'; | |
| import { HttpErrorResponse } from '@angular/common/http'; | |
| import { CustomError } from './custom-error'; | |
| @Injectable() | |
| export class GlobalErrorHandler implements ErrorHandler { | |
| constructor() { } | |
| handleError(error) { | |
| if(error instanceof HttpErrorResponse){ | |
| //write your handler for network errors, may be send to error loggers | |
| } |
This file contains hidden or 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
| export class CustomError extends Error { | |
| constructor(m: string) { | |
| super(m); | |
| // Set the prototype explicitly. | |
| Object.setPrototypeOf(this, CustomError.prototype); | |
| } | |
| } |
This file contains hidden or 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
| import { BrowserModule } from '@angular/platform-browser'; | |
| import { NgModule, ErrorHandler } from '@angular/core'; | |
| import { AppComponent } from './app.component'; | |
| import { GlobalErrorHandler } from './error-handler.service'; | |
| @NgModule({ | |
| declarations: [ | |
| AppComponent | |
| ], |
This file contains hidden or 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
| import { ErrorHandler, Injectable} from '@angular/core'; | |
| @Injectable() | |
| export class GlobalErrorHandler implements ErrorHandler { | |
| constructor() { } | |
| handleError(error) { | |
| console.error(error); | |
| } | |
| } |