Why Laravel reply 200 http code when MethodNotAllowedHttpException? - laravel

Why Laravel reply 200 http code when MethodNotAllowedHttpException?
I Would like to recieve a diferent code, like 500.
I consume laravel routes using angular or postman, and recieve 200 code and is dificult to deal with this.
Below one example:

This is not a error, but the usage of the dd() dump and die helper method. This will always return a 200.
Find all dd(); methods in your project and it should work and return a proper error code. But secondly due to that error being thrown, it could seem like your url is invalid and or not allowing POST calls.

Related

Laravel, api, postman

I am following a grafikart tutorial on the back-end of an API under laravel, but creating a comment module, and since yesterday I have this message why. I think that I come from a call or from a space name but I know ... on postman also it returns to me errors.
postman:
error message:
Add the model namespace to your call, make sure you have a method called allFor
$comments = \App\Comment::allFor();

Laravel 5.1 random 404 errors

I am using laravel 5.1 framework, I have set up my site using WAMP.
I have handled the errors whoops as it is giving response header except 200 OK.
Now the problem here is,
sometimes existing routes [i.e. working the very next moment if I try] return 404 page with response header 200 OK.
I am unable to figure it out that in which case it is returning 404 page.
Note that I have my own 404 page designed which I found in the response.
My controller code is as below:
public function create($program_id)
{
$projects = $this->mock->mockprojectlist($program_id);
return view('mocks.create', compact('program_id', 'projects'));
}
Can anyone help me with this?

REST API from Javascript - Invalid HTTP status code 405

new Parse developer here looking for some help.
I'm trying to call the REST API from my app to log custom analytics, but for some reason the XMLHttpRequest I'm making fails with the error message:
XMLHttpRequest cannot load https://api.parse.com/1/events/marker. Invalid HTTP status code 405
Here is the code I am using to make the request:
xmlhttp.open("POST", "https://api.parse.com/1/events/marker", true);
xmlhttp.setRequestHeader("X-Parse-Application-Id","appidhere");
xmlhttp.setRequestHeader("X-Parse-REST-API-Key","apikeyhere");
xmlhttp.setRequestHeader("Content-Type","application/json");
xmlhttp.send('{"dimensions":{"action":"showDetails"}}');
This is the console output:
OPTIONS https://api.parse.com/1/events/marker (index):3639(anonymous function) (index):3639S.trigger main.js:15(anonymous function) VM625:31(anonymous function) VM623:11S.trigger main.js:15L.zc VM622:132L.nn VM622:132(anonymous function) main.js:13S.trigger main.js:15L.kl VM622:116(anonymous function) main.js:16
XMLHttpRequest cannot load https://api.parse.com/1/events/marker. Invalid HTTP status code 405`
The strangest thing though is that when I make the request using the curl example in the documentation it works perfectly fine. :/ Any ideas what I'm doing wrong? Hoping it's something simple that I'm overlooking. Thanks!
An HTTP 405 error is Method Not Allowed. The resource you're trying to hit does not accept the POST method.
Be certain that the resource you're trying to hit supports POST; if it doesn't, you'll have to change your XMLHttpRequest accordingly.

MethodNotAllowedHttpException with lucadegasperi/oauth2-server-laravel's included AccessTokenFlow POST route

This is my first Laravel project I'm on, and it has been a ton of fun so far.
I'm setting up an OAuth2 server. I have copied the code posted here in to my routes file.
Via this block of code...
Route::post('oauth/access_token', function()
{
return AuthorizationServer::performAccessTokenFlow();
});
I have tried doing http://local.server.com/oauth/access_token and a "MethodNotAllowedHttpException" error.
If there is any other information I could provide that would help you help me, please tell me!
Cheers
If you are typing http://local.server.com/oauth/access_token into the browser URL bar, then you are sending the request:
GET oauth/access_token
However, your route handles a POST request, and since there is no GET route defined, Laravel is responding with MethodNotAllowedHttpException
In order to properly test your route, you will need to send a POST request.

Faking a 404, 500 and

I am creating a simulation game (web service), and need to fake those error pages. As far as I know, and can see, there isn't a way to fake a 404, or 500 etc. Is this right? Are we able to do this programmatically?
I know I could just make a 404 page and redirect to it... But I'm trying to make it a little more realistic.
Returning a 404 or 500 status code to the browser (see your programming language's/framework's documentation for how) will send a real one instead of a fake one.
Copy whatever page your server sends for those particular errors (or just read the existing files if you've specified them explicitly) and write that out, then send the right status code along with it. For example, in PHP:
header("HTTP/1.1 500 Internal Server Error");
Here's how I'd do it using PHP:
<?php
header('HTTP/ 404'); //So that the browser thinks it's a legitimate 404 error.
#readfile($_SERVER['DOCUMENT_ROOT'] . '/404.html') or die('404 Not Found'); //Replace "/404.html" with your 404 page.
?>

Resources