dart-lang / labs

This repository is home to Dart 'labs' packages.
BSD 3-Clause "New" or "Revised" License
21 stars 2 forks source link

Provide a assets.fileExists() function or make assets.serve() throw #137

Open enyo opened 9 years ago

enyo commented 9 years ago

I want to render my own 404 pages, but Assets doesn't give me a clean way to do that.

It would be great if one of those could be implemented:

  1. an assets.fileExists() function, so I can check if the file exists
  2. a way to call assets.serve() so it throws an exception instead of responding with 404 itself.

What I'm doing to get this working is:

try {
  await gae.context.assets.read();
  gae.context.assets.serve();
}
on gae.AssetError {
  // Render my own 404 page
}

which obviously is less than ideal.

enyo commented 9 years ago

If you tell me which version you'd prefer I can create a PR.

sgjesse commented 9 years ago

Having asset.exists([String path]) would be a good API. This only issue is that if the underlying file system is changed between a call to exists and server or read the builtin 404 could still be returned. However for a deployed server the content in build/web is not supposed to change.

Saying that build/web is not supposed to change can also make it possible to cache the result of exists calls and potentially what is read by server or read as well.