Re: [Zotonic-Usr] Customisation of the 404 page

64 views
Skip to first unread message

Andreas Stenius

unread,
Nov 6, 2012, 4:13:19 AM11/6/12
to Zotonic users
Hi,


You can override that to customize the response for various error codes.

//Andreas



2012/11/6 Marek Setnicka <mset...@gmail.com>
Hi guys,

what is the best way to conditionally serve the 404 (or 410) page?
My scenario is simple: I'd like to be able to show a 404 (410) page with a customised content (different from the standard 404 that Zotonic returns) and based on a condition depending on data in the database.

I am not very experienced with Erlang or using Webmachine for that matter.
I have looked at all various options, from using resource_html to using webmachine_resource and have been primarily looking for a Zotonic way. I haven't found such a way.
The way I see doable is to use resource_html and in the html/1 function retrieve the ReqData from z_context (get_reqdata/1), append a custom body to it using webmachine_request:append_to_response_body/2 and then send response back using webmachine_request:send_response/2.
Is there a better way to achieve what I need? Any hints will be much appreciated.


Have a sunny day,
Marek

Marek Setnicka

unread,
Nov 6, 2012, 11:31:57 AM11/6/12
to zotoni...@googlegroups.com
Many thanks, Andreas.

Any idea how to generate a 410 (Gone) page instead of 404?

Marek

Arjan Scherpenisse

unread,
Nov 6, 2012, 4:50:08 PM11/6/12
to zotoni...@googlegroups.com

On 11/06/2012 05:31 PM, Marek Setnicka wrote:
Many thanks, Andreas.

Any idea how to generate a 410 (Gone) page instead of 404?

The templates only allow customization of the HTML content of the error page, not of the error codes itself. Those codes are created by the controller that is used to serve the URL that was requested.

When you're talking about 410 Gone I assume you want to have that indication when you delete a page (rsc) from the database. The default page controller (controller_page) does not yet have the functionality to emit 410 error codes, as this would need an administration of pages which once existed but are now gone ("tombstones").

Patches welcome, of course ;-)

For example, the controller_page could implement webmachine's previously_existed/2 function, which might do a lookup in a tombstone table, which would be filled when a rsc gets deleted.

Arjan

Marc Worrell

unread,
Nov 6, 2012, 5:27:17 PM11/6/12
to zotoni...@googlegroups.com
Such a "rsc_gone" table would be nice.
Especially when you can also give a new url and/or resource id.

- Marc

Andreas Stenius

unread,
Nov 7, 2012, 4:31:40 AM11/7/12
to Zotonic users
Not bad at all! :)


2012/11/6 Marc Worrell <mwor...@me.com>

Marc Worrell

unread,
Nov 7, 2012, 2:37:20 PM11/7/12
to zotoni...@googlegroups.com
Please check this issue and see if this would do the job:


- Marc

Marc Worrell

unread,
Nov 8, 2012, 8:02:15 AM11/8/12
to zotoni...@googlegroups.com
Support for '410 Gone' status tracking has been added.

For now the support is quite simple.
The data model supports a new id (replacing the deleted id) or a new uri.

This is for later functionality where we want to delete a resource, replacing its spot with another resource.

The controllers 'page' and 'id' are modified for support of 410 gone.

- Marc

Marek Setnicka

unread,
Nov 8, 2012, 2:41:27 PM11/8/12
to zotoni...@googlegroups.com
Hi Marc and others,

I'd like to say thank you for being so incredibly efficient and being able to action this thing so fast. You're truly inspirational!


Best wishes,
Marek
Reply all
Reply to author
Forward
0 new messages