mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 20:20:09 +09:00
Fix: error handling on 404
This commit is contained in:
parent
c957d791a6
commit
a4982c7ef3
@ -7,18 +7,31 @@ function App (props) {
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const result = await axios(
|
||||
'https://api.ashcon.app/mojang/v2/user/' + uuid.uuid,
|
||||
);
|
||||
let result = null;
|
||||
try {
|
||||
result = await axios('https://api.ashcon.app/mojang/v2/user/' + uuid.uuid);
|
||||
setData(result.data);
|
||||
} catch (err) {
|
||||
result = 404;
|
||||
setData(result);
|
||||
}
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
if (data === undefined){
|
||||
console.log("[Minecraft: UUID to player's name] データの取得に失敗しました。 / Failed to retrieve data.")
|
||||
return <></>
|
||||
return <>取得中...</>
|
||||
}else {
|
||||
return <>{data.username}</>
|
||||
if (data === 404) {
|
||||
return <p>そのようなプレイヤーは存在しません。</p>
|
||||
} else {
|
||||
return (
|
||||
<div className='has-tooltip'>
|
||||
<span className='tooltip rounded shadow-lg p-1 bg-gray-100 text-red-500 -mt-8 font-mono text-sm'>UUID: {uuid.uuid}</span>
|
||||
<p className="text-2xl">{data.username}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,9 @@ function App (props) {
|
||||
}else {
|
||||
if (data.toString() == "[object Object]") {
|
||||
return <p>取得中です...</p>
|
||||
} else {
|
||||
if (data.toString() == "not_found") {
|
||||
return <></>
|
||||
} else {
|
||||
let dateTime = new Date(parseInt(data.toString()) * 1000);
|
||||
return (
|
||||
@ -60,6 +63,7 @@ function App (props) {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,8 @@ function App (props) {
|
||||
<div className="w-5"></div>
|
||||
<div>
|
||||
<p className="text-2xl text-mono"><GetName uuid={uuid.uuid} /></p>
|
||||
<p className="text-xs">UUID: <span className="font-mono">{uuid.uuid}</span></p>
|
||||
<p><Online uuid={uuid.uuid} /></p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user