mirror of
https://github.com/Findus23/devicedetector.net.git
synced 2024-09-19 15:43:46 +02:00
error handling and limit of ua length
This commit is contained in:
parent
1f615801de
commit
ab7a3e4c4b
2 changed files with 15 additions and 3 deletions
|
@ -12,6 +12,9 @@
|
|||
<div v-if="tooManyRequests" class="box centered">
|
||||
There were too many requests. Please wait a minute before reloading the website.
|
||||
</div>
|
||||
<div v-if="serverError" class="box centered">
|
||||
There was an error on the server: <code>{{serverError}}</code>
|
||||
</div>
|
||||
<div v-if="gotData">
|
||||
<div v-if="!dd.clientInfo && !dd.botInfo" class="box centered">
|
||||
Device Detecter couldn't detect any information about this user agent.
|
||||
|
@ -102,7 +105,8 @@ export default Vue.extend({
|
|||
gotData: false,
|
||||
processingServerSide: false,
|
||||
showJSON: false,
|
||||
tooManyRequests: false
|
||||
tooManyRequests: false,
|
||||
serverError: ""
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -116,6 +120,7 @@ export default Vue.extend({
|
|||
},
|
||||
fetchData(ua: string): void {
|
||||
this.gotData = false;
|
||||
this.serverError = "";
|
||||
this.tooManyRequests = false;
|
||||
this.processingServerSide = true;
|
||||
const req = new XMLHttpRequest();
|
||||
|
@ -124,11 +129,13 @@ export default Vue.extend({
|
|||
if (req.status === 200) {
|
||||
this.dd = JSON.parse(req.responseText);
|
||||
this.gotData = true;
|
||||
this.processingServerSide = false;
|
||||
} else if (req.status === 429) {
|
||||
this.tooManyRequests = true;
|
||||
this.processingServerSide = false;
|
||||
} else {
|
||||
this.serverError = req.responseText;
|
||||
}
|
||||
this.processingServerSide = false;
|
||||
|
||||
}
|
||||
};
|
||||
req.open("GET", baseURL + "?ua=" + ua, true);
|
||||
|
|
|
@ -23,6 +23,11 @@ if (!empty($_GET["ua"])) {
|
|||
$userAgent = $_SERVER['HTTP_USER_AGENT'];
|
||||
}
|
||||
|
||||
if (strlen($userAgent) > 1000) {
|
||||
echo "The user agent has to be shorter than 1000 characters.";
|
||||
http_response_code(500);
|
||||
exit();
|
||||
}
|
||||
|
||||
$dd = new DeviceDetector($userAgent);
|
||||
$dd->setYamlParser(new Symfony());
|
||||
|
|
Loading…
Reference in a new issue