I am wanting to execute a simple test using Pest and using Orcestra Testbench Dusk. However when this happens, I encounter the following in the browser:
This page isn’t working
127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500
My set up is as follows:
MyTest.php
$this->browse(function($browser) {
$browser->visit('/')
->tap(fn() => sleep(3))
->assertSee('Laravel');
});
Pest.php
...
uses(BrowserTestCase::class)->in('Browser');
...
BrowserTestCase.php
class BrowserTestCase extends \Orchestra\Testbench\Dusk\TestCase
{
protected function defineRoutes($router)
{
$router->get('/', function() {
return view('welcome');
});
}
protected function defineEnvironment($app)
{
//set this as wondered if I could get the output of any error rendered
$app['config']->set('app.debug', true);
}
}
Since the HTTP error is 500, it feels like there is an error in my code but I am unsure where/if this is logged anywhere. That said running ./vendor/bin/testbench serve yields no errors.
What am I missing to get this to run my test successfully?
Related
I'm currently building a single page application based on Laravel and VueJS.
Is there any better way then mine to handle errors with axios?
This is how I currently do it when a user clicks on login button:
VueTemplae:
methods : {
authenticateUser() {
axios.post('/api/login', this.form).then(() => {
this.$router.push({name : 'home'});
}).catch((error) => {
this.error = error.response.data.message;
});
}
}
Api route:
public function login() {
try {
// do validation
} catch(Exception) {
// validation failed
throw new Exception('login.failed');
}
// manually authentication
if(Auth::attempt(request()->only('email', 'password'))) {
return response()->json(Auth::user(), 200);
}
// something else went wrong
throw new Exception('login.failed');
}
Unfortunately, throwing an exception always prints an internal server error into the console.
If I return something else than an exception, axios always executes then().
Is there any way to prevent this or a better way to handle axios responses?
Thank you!
Your API needs to return a response with a 4XX status code in order for the catch block to fire in your Vue component.
Example:
After you catch the error on the API side, send a response with status code 400 Bad Request. It will be formatted similarly to your successful login response, but with an error message and 400 status code instead of 200.
I have been trying to diagnose a http problem for what seems forever now.
I thought I would go back to a very simple sample Ionic (Angular) application I can use to test, where I have the following test code...
public onClick() : void {
this.http.get(this.url).subscribe(res => {
this.result = res.statusText;
console.log(res);
}, error => {
this.result = `failed ${error.statusText}`;
console.log(error);
});
}
The url just comes from an input.
If I force an error, (eg put an incorrect url), I notice the error from the observable always has a status os 0, and no statusText. In the browser network tab, I see the 404 as expected...
identityx 404 xhr polyfills.js:3 160 B 10 ms
Is there a way to get better error information back from the http call, rather than just 0 all the time (and no status text)? I've look through the error object, but can't see anything.
Thanks in advance!
// Edit: Hm...this is an firebug bug in firefox. On chrome it works...
I'm using Laravel 5.3 with Vue 2.0 and the axios ajax library.
Here is a test controller, where i return a response from laravel:
public function testMethod() {
return response('this is an error', 500);
}
Here is my ajax call:
http(`fetch-data`).then(response => {
const data = response.data;
console.log(data);
}).catch(error => {
console.log(error); // <- This doens't work, he show my nothing
alert(error);
});
The problem is, i need the error message which is returned from laravel into my client catch. But if i console.log them, he show me nothing. If i alert the error, he gives me the following message: Error: Request failed with status code 500.
Why can't i access something like error.statusCode, error.statusMessage?
Try
return response()->json('this is an error', 500);
I am running a site on my VirtualBox Ubuntu. Trying to make an Ajax request I get a 403 error. Now I know Linux is rather weird with permissions. My Linux adept friend tried and failed to help me over about an hour. Code is below. Let me know if more information is needed.
JS:
function emailValidation (email) {
$.post('../../application/controller/account/emailValidation',
{'email':email}
);
}
PHP:
function emailValidation ($email) {
$this->load->helper('email');
if (valid_email('$email')) {
return true;
} else {
return false;
}
}
ERROR: "You don't have permission to access /application/controller/account/emailValidation on this server."
The path in my Ajax was incorrect. It needed to be /account/emailValidation. It's a noob mistake. Thanks for helping though.
When using the following composer package bitgandtter/google-api for google php api client since I'm using it in combination with laravel 4 I get the following error redirect_uri_mismatch. My code looks like this(which is located under app/lib using the PSR-0 spec):
class Google {
private $client;
private $token;
public function __construct($code)
{
$this->client = new Google_Client();
$this->client->setApplicationName("camelCaseD");
$this->client->setClientId('SOMENUMBERS.apps.googleusercontent.com');
$this->client->setClientSecret('PRECIOUS');
$this->client->setRedirectUri('http://localhost:9000/auth/google');
$this->client->authenticate($code);
}
}
My routes are:
Route::group(['prefix' => 'auth'], function()
{
Route::post('google', function()
{
$postInput = file_get_contents('php://input');
try
{
$google = new Google($postInput);
} catch (Exception $e)
{
return Redirect::to('signin')->with('error', $e->getMessage());
}
});
});
I'm using the official google plus sign in button to log the user in then passing the authorization code to my server via $.ajax().
Here's what my api console settings look like:
I got that similar error. To resolve mine, I went to google console and reset the secret. I also made sure the Authorized JavaScript origins was set to the correct address.
http:// localhost :900/auth/google
is a directory or a page?
Maybe if it is a directory, the final url is different (like http:// localhost :900/auth/google/index.php) and Google does a control between 2 string, but they are different.