0

I am using Http to connect to the server.

Server automatically blocks users who are not authorized by giving me 403 forbidden error.

Though I don't have to use AuthGuard (coz server is doing it for me), but I still want to show some message when the 403 forbidden error is returned rather than show just blank white page.

So my question is.. is it possible to use this forbidden 403 error in Angular2 so that I can display something when the error is returned?

Like

if (errorMessage == 403) {
showModal () }

maybe like this?

2
  • It's possible, since you should be getting a response from the server. You need to make a 403 error HTML page and present it Commented May 9, 2017 at 2:05
  • and could you tell me how to do that? like create another component for 403 error html page? Commented May 9, 2017 at 2:07

1 Answer 1

1

The simples example is just

@Inject export default class SomeService {
  constructor(readonly http: Http) {}

  getData() {
    return this.http.get('api/path-to-something')
      .catch(error => {
        if (error.status === 403) {
          // Just using alert for simplicity's sake. 
          alert('You don't have sufficient access to do that!');
        }
        throw error;
      })
      .map(response => response.json());
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.