question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Public API doesn't work in error.hbs template

See original GitHub issue

Issue Summary

Public API doesn’t work in error.hbs template

Steps to Reproduce

  1. I had tried use this code for testing error page with enabled api
$.get(ghost.url.api('posts', {limit: "all", include: "tags"})).done(function(data){
      searchData = data.posts;
      console.log(searchData);
 })

and I get this message:

ghost is not defined

Technical details:

  • Ghost Version: 0.8.0
  • Node Version: 0.12.7
  • Browser/OS: chrome
  • Database: mysql

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
ErisDScommented, Jun 12, 2016

I’ve always considered that it is bad practice to use the main layout on the error page, and more specifically to include ghost_head or foot on the error template. I think it’s better to have a 500 error page that can render freely of any other aspect of the software, to minimise the chance of causing the error to be thrown again.

The server-side error environment is quite different to rendering a normal page of your theme, lots of things aren’t loaded, and the reason for this particular issue is that if you call ghost_head from an error page it simply exits rather than adding anything, so as not to cause any more errors…

The default error template provided by Ghost is entirely stand-alone as an example of what we consider best practice here. You can see this file here: user-error.hbs.

However, I’ve seen that using the default layout in the error template is common amongst themes, and I have a feeling the reason for that is symptom of a different problem - the fact that error.hbs is used for both 404s as well as 5xx errors. It’s pretty common to want to heavily customise a 404 page and render all sorts of useful stuff (such as search) on that page to get a user to stay on the site, meanwhile I think it’s fairly standard to have a very simple 5xx template.

I’d propose extending the error handling system to support error-404.hbs and error-500.hbs, to handle different sorts of errors differently. I’d propose that ghost_head should still not output anything if we’re on a 500 or 5xx error, but that it would be ok to output some things (such as the API scripts) if we’re on a 404 page?

0reactions
ErisDScommented, Mar 1, 2017

Closing in favour of the feature spec: #8079

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handlebars example not working - Stack Overflow
I realized the problem. The server-side handlebars is interfering with client-side handlebars. All the {{}} tags that are meant for the client- ...
Read more >
hbs files are not copied to dist folder · Issue #42 - GitHub
I'm still getting the error that implies that the templates folder is not transpiled to the dist folder. What could the problem possibly...
Read more >
How to Handle Errors in an Express and Node.js App
Express knows this and makes handling errors in our API a breeze. In this post, I will explain how to handle errors in...
Read more >
Introduction | Handlebars
Handlebars is a simple templating language. It uses a template and an input object to generate HTML or other text formats.
Read more >
Node.js application error message: "Cannot GET" URL
js application error message: "Cannot GET" URL. This article discusses a problem that may occur when you try to run a Node.js application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found