Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed apiType and broken error handling #10536

Merged
merged 4 commits into from
Feb 26, 2019
Merged

Conversation

kirrg001
Copy link
Contributor

@kirrg001 kirrg001 commented Feb 25, 2019

PR contains a couple of clean commits. Please look at each commit individually 👍

A couple of regression tests were broken, which made me curious.

  1. API v2 pipeline changes the error handler, which broke the error handling for the site, because it expects an error and not an object with attrs. If you add a catch handler, you expect to get an error and not an object.

  2. apiType was always undefined for functional calls e.g. api.v2.settings.edit({..} {context: {internal:true}}) returned true forisContentAPI(). The apiType was only handled on http layer, not on functional layer.

Please use "rebase & commit"!

  • review & test @allouis
  • review & test @gargol
  • @gargol Kevin pushed some mobiledoc/html changes (4f9e687), which breaks some regression importer & posts tests. Can you please ask him if they are okay to ignore for now?

no issue

- throwing an object from a catch handler is not a good idea
- unexpected and broke functional call to API (always returned a 500, because API returned {err: err, method: ...}
no issue

- was unable to revert TryGhost@9dd7aff, because it contains members changes
- functional calls did not work correctly, because the content and admin ctrl differentiation happend in the web layer
- `isContentAPI` returned true for `api.v2.settings.edit(data, {context: {internal:true{})`
- content & admin API are using different controllers
- we can just tell which ctrl is content API and which is not
- the direction fits for the content & admin API split
@@ -156,9 +159,6 @@ const pipeline = (apiController, apiUtils) => {
})
.then(() => {
return frame.response;
})
.catch((err) => {
throw {err, docName, method};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gargol Which consequences has this change on the error message right now? e.g. the site uses browse & read only, which most common error is a 404.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as frameOptions are populated with docName and method that map to these rules: https://github.com/TryGhost/Ghost/blob/master/core/server/web/shared/middlewares/error-handler.js#L96-L106 there should be no effect. The 404 for read/browse would map to read/list {resource} and this translation:

"NotFoundError": "Resource not found error, cannot {action}.",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect 👍

@@ -103,10 +103,6 @@ module.exports = {
return shared.pipeline(require('./slack'), localUtils);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every content API ctrl uses the pattern {resource}-public, except of this ctrl. Consistency change.

@@ -10,7 +10,7 @@ class Frame {
this.user = {};
Copy link
Contributor Author

@kirrg001 kirrg001 Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allouis Please review & test the apiType change good as possible 👍 Thanks!

return shared.pipeline(require('./tags-public'), localUtils, 'content');
},

get publicSettings() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs renaming, not important now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be best tackled during #10106, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes perf 👍


// CASE: apiType = 'content' for HTTP Content API
return frame.apiType === 'content' || isPublic;
return frame.apiType === 'content';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter which context you have. If you request content API, you are in content ctrl land. Same for admin.

@allouis
Copy link
Contributor

allouis commented Feb 26, 2019

This looks good - I will test A$AP

@naz
Copy link
Contributor

naz commented Feb 26, 2019

Have tested the part which had to do with changes in error handling, works great and is a lot cleaner than the previous implementation 👍

@kirrg001 kirrg001 merged commit 5a52336 into TryGhost:master Feb 26, 2019
@kirrg001
Copy link
Contributor Author

@allouis Merged. Can you please confirm back if you have tested the apiType change? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants