Skip to content

Commit

Permalink
improve error handling for lookup user (#142)
Browse files Browse the repository at this point in the history
- disable "Find User" when input is empty
- return 404 instead of 500 when not found
- skip axios error notification interceptor and manually handle error
- fix error message
  • Loading branch information
jxjj authored Apr 3, 2024
1 parent f1248c0 commit e4db731
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function userLookup(Request $request) {
} else if (count($outputArray) == 0) {
$returnData['status'] = "Error";
$returnData['message'] = "We couldn't find that user.";
$code = 500;
$code = 404;
} else {
$returnData['status'] = "Partial";
$returnData['users'] = $outputArray;
Expand Down
23 changes: 20 additions & 3 deletions resources/js/components/UserLookup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@

<div class="form-group row">
<div class="col-sm-3">
<button class="btn btn-primary" @click="lookupUser">Find User</button>
<button
class="btn btn-primary"
:disabled="!userLookupId"
@click="lookupUser"
>
Find User
</button>
</div>
</div>
<div class="row">
Expand All @@ -59,6 +65,7 @@
<script>
import Modal from "./Modal.vue";
import PersonSearch from "./PersonSearch.vue";
import { axios } from "@/utils";
export default {
components: {
Expand Down Expand Up @@ -96,8 +103,18 @@ export default {
});
},
lookupUser: function () {
if (!this.userLookupId) {
return;
}
axios
.post("/api/user/lookup", { users: this.userLookupId })
.post(
"/api/user/lookup",
{ users: this.userLookupId },
{
skipErrorNotifications: true,
},
)
.then((res) => {
if (res.data.users.length == 1) {
this.$router.push({
Expand All @@ -114,7 +131,7 @@ export default {
}
})
.catch((err) => {
this.findUserError = err.response.data.message;
this.findUserError = err.data.message;
});
},
},
Expand Down

0 comments on commit e4db731

Please sign in to comment.