Comments (10)
it seems as though the way to do it is to replace the resource with
undefined
, but that logic is only applied to Collections
Yes, this is intentional, if I remember my thought process correctly. Basically, it's ok to remove a single resource from a response that returns a collection, because the resulting response (just the collection minus one item) is still a valid response. By contrast, a single resource request that doesn't return a resource needs to be an error (probably, but not necessarily, a 404; could also be a 403 etc).
So, I think the way to do what you want is to have your beforeRender
transform throw an APIError
with the appropriate details. Try that, and let me know if for some reason it doesn't work :)
from json-api.
What I'm doing to getting /users
which right now returns all users, but should return just the authenticated user (or more, depending on privileges). beforeRender
is being called once on each of the users found.
Is this what you're talking about with throwing an APIError
?
var APIError = require('json-api').types.Error
module.exports = {
urlTemplates: {
self: 'https://localhost:3000/users/{id}',
relationship: 'https://localhost:3000/users/{ownerId}/relationships/{path}'
},
beforeRender: function(resource) {
throw new APIError(500, undefined, 'Nope')
}
}
This just hangs for me. Same result if I return the error.
from json-api.
Ahh, ok. Then the fact that returning undefined
doesn't work is just a bug. I think I know where it's coming from, and will push a fix in a sec.
from json-api.
This is fixed now, so you should be able to just return undefined
for the resources you want to remove. See the commit message if you're curious about what the bug was.
Edit: of course, you'll have to update to the newest version, 2.8.2
from json-api.
Works perfectly. Thanks so much!
from json-api.
Absolutely! Please lmk if you hit any other problems. Ideas for the library are also always welcome!
from json-api.
Do you want me to report hangs when I find them? I've bumped into a few while doing things wrong. Now that I have things set up correctly it's all working fine, but it might be nice to give proper errors in those cases.
from json-api.
Yeah, reporting those would be much appreciated! I definitely coded this library for the happy path, so the code isn't great about throwing errors where it should (though that's starting to improve as we add more tests).
from json-api.
Sweet, I'll open some more issues. I'll send in a PR or two as well If I manage to get my head around generators
from json-api.
Awesome! Thank you! I'll take a look at those issues later tonight :)
from json-api.
Related Issues (20)
- Filtering not working for me HOT 7
- Patch requests problem HOT 1
- Performance: Fetching a relationship needlessly loads the whole resource HOT 1
- Filtering relationships HOT 1
- Duplicate scheme in root object.
- json-api reads from Raw URLs instead of decoded HOT 3
- Allow feature to populate embedded data HOT 2
- Fastify integration HOT 3
- Incorrect Content-type on responses HOT 5
- Provide Koa example
- Filter not working HOT 8
- andWhere query is not working HOT 11
- Issue with serverless
- Add debug environment variable on README.md HOT 1
- Suggestion for Projects
- Example in README.md has unused variable 'opts' HOT 1
- Express `req.host` deprecation warning HOT 3
- How to work around `id` and `type` field names? HOT 4
- Svelte js Express Firebase?
- Please give a workable example HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-api.