1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-17 12:30:32 +09:00

chore: suppress error reporting for missing name

This commit is contained in:
uetchy 2019-12-23 21:49:42 +09:00
parent 5f35af4aef
commit 4a7687eafe

View File

@ -67,6 +67,19 @@ interface Response {
availability: boolean; availability: boolean;
} }
class APIError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, APIError.prototype);
}
}
class NotFoundError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, NotFoundError.prototype);
}
}
export const DedicatedAvailability: React.FC<{ export const DedicatedAvailability: React.FC<{
name: string; name: string;
query?: string; query?: string;
@ -95,7 +108,7 @@ export const DedicatedAvailability: React.FC<{
) as Response; ) as Response;
if (response.error) { if (response.error) {
throw new Error(`${service}: ${response.error}`); throw new APIError(`${service}: ${response.error}`);
} }
return ( return (
@ -135,7 +148,7 @@ export const ExistentialAvailability: React.FC<{
const response = useFetch(target, undefined, {metadata: true}); const response = useFetch(target, undefined, {metadata: true});
if (response.status !== 404 && response.status !== 200) { if (response.status !== 404 && response.status !== 200) {
throw new Error(`${name}: ${response.status}`); throw new NotFoundError(`${name}: ${response.status}`);
} }
const availability = response.status === 404; const availability = response.status === 404;
@ -219,6 +232,9 @@ class ErrorBoundary extends React.Component<
} }
componentDidCatch(error: Error, errorInfo: any) { componentDidCatch(error: Error, errorInfo: any) {
if (error instanceof APIError || error instanceof NotFoundError) {
return;
}
sendError(error, errorInfo).then((eventId) => { sendError(error, errorInfo).then((eventId) => {
this.setState({eventId}); this.setState({eventId});
}); });