forwardemail / forwardemail/superagent

How to show error of superagent request when I gor error on server?

Open
#1,616 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I added "superagent": "^6.1.0" into my Laravel 8 app and when I got error on Laravel side I try
to catch it and show in flas message, like:

superagent
.get('/profile/user_prop')
// .send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
// .set('X-API-Key', 'foobar')
.set('accept', 'json')
.end((err, res) => {
console.log('err::')
console.log(err)

console.log('res::')
console.log(res)
if( res.error ) {
console.log('res.error::')
console.log(res.error)
console.log('res.text::')
console.log(res.text)
popupErrorMessage( res.statusText + ( res.body != null ? ' : ' + res.body.message : '') )
} else {
$("#div_user_props").html(res.body.html);
}
// Calling the end function will send the request
});

It works ok, when I return error message in json return :

$userProfile = Auth::user();
if ( empty($NonFoundUserProfile) ) {
return response()->json(['message' => 'No Logged user !'], 500);
}

But in case of error in not in return block, like :

$userProps = UserProp
::getByUYYserId($userProfile->id) // NONEXISTING METHOD
->orderBy('user_props.created_at', 'desc')
->get()
->map(function ($userPropItem) {
return $userPropItem;
})
->all();

I can not get error message and the only thing I found in browsers console :
https://prnt.sc/xi7o13
and
https://prnt.sc/xi7pnn
the only place where I saw an error message is res.text : https://prnt.sc/xi7x1q
but that is string literal of full error and if there is a way to get only this error text and flash it ?

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.