Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] modernize TimeoutError example code #7043

Merged
merged 2 commits into from Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions packages/adapter/addon/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ InvalidError.prototype.code = 'InvalidError';
```app/routes/application.js
import Route from '@ember/routing/route';
import { TimeoutError } from '@ember-data/adapter/error';

export default Route.extend({
actions: {
error(error, transition) {
if (error instanceof TimeoutError) {
// alert the user
alert('Are you still connected to the internet?');
return;
}

// ...other error handling logic
import { action } from '@ember/object';

export default class ApplicationRoute extends Route {
@action
error(error, transition) {
if (error instanceof TimeoutError) {
// alert the user
alert('Are you still connected to the Internet?');
return;
}

// ...other error handling logic
}
});
}
```

@class TimeoutError
Expand Down Expand Up @@ -237,20 +237,20 @@ AbortError.prototype.code = 'AbortError';
```app/routes/application.js
import Route from '@ember/routing/route';
import { UnauthorizedError } from '@ember-data/adapter/error';

export default Route.extend({
actions: {
error(error, transition) {
if (error instanceof UnauthorizedError) {
// go to the sign in route
this.transitionTo('login');
return;
}

// ...other error handling logic
import { action } from '@ember/object';

export default class ApplicationRoute extends Route {
@action
error(error, transition) {
if (error instanceof UnauthorizedError) {
// go to the login route
this.transitionTo('login');
return;
}

// ...other error handling logic
}
});
}
```

@class UnauthorizedError
Expand Down Expand Up @@ -283,24 +283,25 @@ ForbiddenError.prototype.code = 'ForbiddenError';
```app/routes/post.js
import Route from '@ember/routing/route';
import { NotFoundError } from '@ember-data/adapter/error';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default Route.extend({
export default class PostRoute extends Route {
@service store;
model(params) {
return this.get('store').findRecord('post', params.post_id);
},

actions: {
error(error, transition) {
if (error instanceof NotFoundError) {
// redirect to a list of all posts instead
this.transitionTo('posts');
} else {
// otherwise let the error bubble
return true;
}
}
@action
error(error, transition) {
if (error instanceof NotFoundError) {
// redirect to a list of all posts instead
this.transitionTo('posts');
} else {
// otherwise let the error bubble
return true;
}
}
});
}
```

@class NotFoundError
Expand Down