Commit Graph

17 Commits

Author SHA1 Message Date
Naz
7b009bf1fe Enabled shared caching of 404 error responses
refs https://github.com/TryGhost/Toolbox/issues/410

- The 'private' value in 'Cache-Control' response header for all errors made it impossible for shared caches (e.g.: Fastly, Cloudflare) to cache 404 responses efficiently.
- The change substitutes 'max-age=0' which should not effect the browser cache behavior but would allow shared caches to process such requests efficiently.
- A more loose caching logic only applies to 404 responses from GET requests that are not user-specific (non-authenticated, non-cookie containing requests)
2022-09-26 14:54:50 +08:00
Naz
2acb0fca74 Refactored error cache control logic to middleware
refs https://github.com/TryGhost/Toolbox/issues/410

- This is groundwork for split cache-control rules for Admin app endpoints and the rest of Ghost apps.
2022-09-26 14:54:50 +08:00
Hannah Wolfe
af94855349 Removed bluebird catch predicates from API endpoints
refs: https://github.com/TryGhost/Ghost/issues/14882

- I found a common pattern where catch predicates were being used to catch non-existent models in destroy methods, and sometimes elsewhere in the API endpoints
- The use of predicates is deprecated, and we're working to remove them from everywhere, so that we can remove bluebird
- In order to still handle these errors correctly, we needed a small change to mw-error-handler so that it can detect EmptyResponse errors from bookshelf, as well as 404s
Note: there is a small change as a result of this - the context on these errors now says "Resource not found" instead of "{ModelName} not found".
- I think this is acceptable for now, as we will be reviewing these errors in more depth later. It's quite easy to make changes, we just have to decide what with proper design input
2022-08-24 11:27:09 +01:00
Hannah Wolfe
0ad0cee19b Removed unused jsonErrorRenderer + renamed V2
- As of Ghost 5.0 we only use the V2 version of jsonErrorRenderer
- Removed the old one, and renamed the V2 to not have a suffix any more
- Added 100% coverage to tests whilst here
2022-05-06 15:45:41 +01:00
Hannah Wolfe
9e6f5c5194 Updated copy for accept-version errors
- Copy has been updated and approved now :)
2022-05-04 13:04:40 +01:00
Hannah Wolfe
e4af12e5c0 Added additional ghostErrorCode note for the major
refs: https://github.com/TryGhost/Toolbox/issues/316

- getting ready to do a major bump
2022-05-02 14:45:16 +01:00
Hannah Wolfe
fc9e61ff35 Fixed linting error
- trying to call new RequestNotAcceptableError with a variable triggers a lint warning in newer versions of eslint-plugin-ghost
- this workaround is worth it for the safety of not allowing single strings to be passed in!
2022-05-02 13:47:29 +01:00
Hannah Wolfe
a6e204b829 Deprecated handleJSONResponse
- this middleware block is used in v4 but not in v5
- we want to remove it and then rename handleJSONResponseV2 so that we have one single consistent error handling block
2022-05-02 13:43:48 +01:00
Naz
258b0acc51 Added specific 'code' properties for RequestNotAcceptableError
refs https://github.com/TryGhost/Toolbox/issues/292

- There's a need to distinguish different types of RequestNotAcceptableError erros by their code. The code is also having an instructional name to give it more explicit utility (nice clue for a developer seeing the error)
2022-04-21 15:57:43 +08:00
Naz
ebc8881d65 Renamed variables to match their content
refs https://github.com/TryGhost/Toolbox/issues/280

- The naming of variables should've been vice-versa. Should make the code less confusing now
2022-04-13 13:30:16 +08:00
Naz
ee7655213e Added 406 response for outdated Ghost instance
refs https://github.com/TryGhost/Toolbox/issues/280

- When an outdated client receives a 404 as a response there's no clear way to act on it. Plain 404 says nothing about need to update.
- In such cases the resourceNotFound handler should return a 406 error indicating the Ghost instance needs an update.
2022-04-08 12:52:41 +08:00
Naz
88500e0704 Added 406 response for outdated API clients
refs https://github.com/TryGhost/Toolbox/issues/280

- When an outdated client receives a 404 as a response there's no clear way to act on it. Plain 404 says nothing about need to update.
- In such cases the resourceNotFound handler should return a 406 error indicating the client need to update.
2022-04-08 12:40:37 +08:00
Daniel Lockyer
10e97cad23 Handled unknown errors when preparing user message
- in the event we get an unknown error bubble up, we don't handle the
  templating on the error name
- `@tryghost/tpl` throws an error because we pass an undefined string:
  `Cannot read properties of undefined (reading 'replace')`
- this commit adds handling to fallback to a different user message in
  that event so we don't cause a 500 error
2022-03-24 10:06:55 +00:00
Sam Lord
d65ba072f9 Split prepareError from prepareStack
no issue

Change to error handling caused all theme errors to be reported in Sentry, this fix (and a respective fix in Ghost) allows the error to be prepared for sentry before replacing the stack
2022-03-21 09:38:05 +00:00
Sam Lord
51588c6a24 Ensure Sentry is triggered before replacing the stack trace
refs: https://github.com/TryGhost/Team/issues/1369

If we prepare the error for users to view before using Sentry, then the error passed to Sentry will have the stack trace removed for production environments.

@tryghost/errors@1.2.5 also made it so that the error is not mutated, but cloned and a new one is returned.
2022-03-11 10:47:26 +00:00
Sam Lord
6a5ea251a5 Fix usage of member function for errors
no issue
2021-12-14 14:07:07 +00:00
Sam Lord
4ef7c974a3 Add @tryghost/mw-error-handler
refs: https://github.com/TryGhost/Toolbox/issues/137
Package includes same logic as was in the Ghost codebase but needs Sentry injected
2021-12-07 18:40:46 +00:00