1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-23 17:56:28 +02:00
onion/js/models/errors.js
2015-12-07 11:48:28 +01:00

32 lines
862 B
JavaScript

'use strict';
import React from 'react';
import ErrorNotFoundPage from '../components/error_not_found_page';
export class ResourceNotFoundError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
this.message = message;
// `captureStackTrace` might not be available in IE:
// - http://stackoverflow.com/a/8460753/1263876
if(Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor.name);
}
}
handler(component, err) {
const monkeyPatchedKey = `_${this.name}MonkeyPatched`;
if(!component.state[monkeyPatchedKey]) {
component.render = () => <ErrorNotFoundPage message={err.message} />;
component.setState({
[monkeyPatchedKey]: true
});
}
}
}