Welcome! Log In Create A New Profile

Advanced

Re: nginx returns html instead of json response

All files from this thread

File Name File Size   Posted by Date  
nginxtest.conf 3.6 KB open | download kaushalshriyan 11/07/2022 Read message
nginxtest.conf 3.6 KB open | download kaushalshriyan 11/08/2022 Read message
nginxtest.conf 3.6 KB open | download kaushalshriyan 11/09/2022 Read message
nginxtest.conf 3.6 KB open | download kaushalshriyan 11/14/2022 Read message
nginxtest.conf 3.6 KB open | download kaushalshriyan 11/22/2022 Read message
November 18, 2022 12:42PM
On Fri, Nov 18, 2022 at 9:37 PM Francis Daly <francis@daoine.org> wrote:

> On Fri, Nov 18, 2022 at 07:07:41PM +0530, Kaushal Shriyan wrote:
> > On Thu, Nov 17, 2022 at 10:57 PM Francis Daly <francis@daoine.org>
> wrote:
>
> Hi there,
>
> > Please let me know if you need any additional information and I look
> > forward to hearing from you. Thanks in advance.
>
> When the request is for "/apis/unique_id", what file on the filesystem
> do you want nginx to ask drupal to use?
>
>
Thanks Francis for your email response. Let me explain with two different
scenarios :-

*Scenario 1 *
500 errors occurred in any random page of the site for example -
https://mydrupalsite.com/randompath , in that case we want Nginx to provide
an HTML error page. And this is working as we have set up a custom HTML
page and configured Nginx 500 error to point to that HTML page. We don't
have any issue here

*Scenario 2 *
500 error occurred when the user tried to access the page -
https://mydrupalsite.com/apis or https://mydrupalsite.com/apis/unique_id .
Here we want a json response that Drupal is sending. Now we can't say what
specific file Nginx should use in this case to display the JSON response.
As when a user is trying to access these pages , in the backend , to serve
this request Drupal is processing N number of files, now among those files
in any file that 500 exceptions can occur. At code level we are just
handling that and sending JSON responses. Like below.
try{
$node_new->save();
}
catch(\Exception $e) {
$output = [
"type" => "/problems/API-saving-error",
"title" => $this->t("Issue occurred while saving the
API."),
"detail" => $this->t("There are some wrong inputs passed
to DB which caused this issue."),
];
return new JsonResponse($output, 500);
}

So here you can see that we handled and sent the JSON response , now we
can't tell Nginx which file we want to present , as the JSON response can
come from any file where 500 exceptions are handled. (edited)

And moreover the content of the JSON response also varies based on the
reason behind that 500 exception, as we try to give relevant messages to
the user , so if 500 errors occurred in any other php file the JSON
response content can be different.

So we want Nginx to display this JSON response whatever Drupal is sending
instead presenting the default HTML page which is configured for 500 error

So , it's not like that we need to tell Nginx what file of the filesystem
Nginx can use to display 500 error for https://mydrupalsite.com/apis or
https://mydrupalsite.com/apis/unique_id, rather we want Nginx to display
whatever Drupal is sending. And it can be easily achieved if we don't
configure 500 error pages at Nginx , in that case whatever Drupal is ending
that only will be displayed. Problem is that we have to keep that 500 error
page configuration at Nginx and at the same Nginx should not use that error
page for these two types of URLs- https://mydrupalsite.com/apis or
https://mydrupalsite.com/apis/unique_id

Please let me know if you need any additional information and I look
forward to hearing from you. Thanks in advance.

Best Regards,

Kaushal
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

nginx returns html instead of json response

kaushalshriyan November 07, 2022 10:32AM

Re: nginx returns html instead of json response

Dan G. Switzer, II November 07, 2022 11:10AM

Re: nginx returns html instead of json response Attachments

kaushalshriyan November 07, 2022 12:48PM

Re: nginx returns html instead of json response

Dan G. Switzer, II November 07, 2022 01:22PM

Re: nginx returns html instead of json response

Maxim Dounin November 08, 2022 12:50AM

Re: nginx returns html instead of json response Attachments

kaushalshriyan November 08, 2022 02:56AM

Re: nginx returns html instead of json response Attachments

kaushalshriyan November 09, 2022 01:16PM

Re: nginx returns html instead of json response

Francis Daly November 11, 2022 04:08AM

Re: nginx returns html instead of json response

kaushalshriyan November 11, 2022 05:52AM

Re: nginx returns html instead of json response Attachments

kaushalshriyan November 14, 2022 09:56AM

Re: nginx returns html instead of json response

kaushalshriyan November 16, 2022 12:00PM

Re: nginx returns html instead of json response

Sergey A. Osokin November 16, 2022 04:42PM

Re: nginx returns html instead of json response

kaushalshriyan November 16, 2022 08:20PM

Re: nginx returns html instead of json response

Francis Daly November 17, 2022 12:28PM

Re: nginx returns html instead of json response

kaushalshriyan November 18, 2022 08:40AM

Re: nginx returns html instead of json response

Francis Daly November 18, 2022 11:06AM

Re: nginx returns html instead of json response

kaushalshriyan November 18, 2022 12:42PM

Re: nginx returns html instead of json response

Francis Daly November 18, 2022 01:32PM

Re: nginx returns html instead of json response

kaushalshriyan November 19, 2022 10:42AM

Re: nginx returns html instead of json response

Francis Daly November 21, 2022 02:22PM

Re: nginx returns html instead of json response Attachments

kaushalshriyan November 22, 2022 09:24AM

Re: nginx returns html instead of json response

Francis Daly November 23, 2022 12:50PM

Re: nginx returns html instead of json response

kaushalshriyan November 23, 2022 12:58PM

Re: nginx returns html instead of json response

Francis Daly November 23, 2022 01:10PM

Re: nginx returns html instead of json response

kaushalshriyan November 29, 2022 11:30AM

Re: nginx returns html instead of json response

kaushalshriyan November 30, 2022 12:48PM

Re: nginx returns html instead of json response

Francis Daly December 01, 2022 02:48PM

Re: nginx returns html instead of json response

kaushalshriyan November 23, 2022 12:52PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 231
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready