mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
32 lines
862 B
JavaScript
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
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|