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

fix: propagate status code from platform api when routing wiki requests #410

Merged
merged 7 commits into from
Jan 16, 2024

Conversation

m90
Copy link
Contributor

@m90 m90 commented Jan 11, 2024

Ticket: https://phabricator.wikimedia.org/T343744

I tested this locally by:

  • requesting a wiki that does not exist, receiving a 404
  • hard coding an error for a certain wiki in api, seeing a 500
diff --git a/app/Http/Controllers/Backend/WikiController.php b/app/Http/Controllers/Backend/WikiController.php
index 2343cd3..b8469ff 100644
--- a/app/Http/Controllers/Backend/WikiController.php
+++ b/app/Http/Controllers/Backend/WikiController.php
@@ -13,6 +13,9 @@ class WikiController extends Controller
     public function getWikiForDomain(Request $request): \Illuminate\Http\JsonResponse
     {
         $domain = $request->input('domain');
+        if ($domain === 'thirdwiki.wbaas.localhost') {
+            throw \Exception("THE DINOSAURS ESCAPED");
+        }
 
         // XXX: this same logic is in quickstatements.php and platform api WikiController backend
         try {

@m90
Copy link
Contributor Author

m90 commented Jan 15, 2024

The entire GlobalSet class is a bit twisted and this PR does not necessarily improve it as it somehow tries to follow the current call chain. We might also think about rewriting this thing in its entirety.

@m90 m90 force-pushed the fr/50x-on-api-error branch from fcfcf70 to 6d0272e Compare January 15, 2024 08:34
@m90 m90 force-pushed the fr/50x-on-api-error branch from 6d0272e to b7666ab Compare January 15, 2024 08:46
dist-persist/wbstack/src/Info/GlobalSet.php Outdated Show resolved Hide resolved
class GlobalSet {

/**
* @param string $requestDomain A request domain, or 'maint' Example: 'addshore-alpha.wiki.opencura.com'
* @return bool was the global successfully set?
* @return void
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this makes sense and probably propagating the precise nature of the failure with an Exception.

In any case this probably makes sense and is then super clear that this is really a side effect only function.

Naturally trying to write this in a clean way is pretty hard since the desired behaviour is charging around a setting a load of globals

*/
public static function forDomain( $requestDomain ) {
public static function forDomain($requestDomain) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So the linting here looks "funny" because MediaWiki uses a very non-php standard code style. No objection to this being changed here since we don't lint this anyway but perhaps in future we should add linting to match the MediaWiki style to this weird codebase in dist-persist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean if we want a code style, then it should be applied everywhere. I just tried to make it consistent per function. Which is probably futile ...

dist-persist/wbstack/src/Info/GlobalSet.php Outdated Show resolved Hide resolved
dist-persist/wbstack/src/Info/GlobalSet.php Outdated Show resolved Hide resolved
dist-persist/wbstack/src/Info/GlobalSet.php Show resolved Hide resolved
@tarrow
Copy link
Contributor

tarrow commented Jan 15, 2024

@m90
Copy link
Contributor Author

m90 commented Jan 15, 2024

If you want to add more "formal" testing you can add stuff to

Ah I didn't know about these, that's very helpful.

@m90 m90 force-pushed the fr/50x-on-api-error branch from 26c9b6c to 0b9240f Compare January 15, 2024 11:22
@m90 m90 force-pushed the fr/50x-on-api-error branch from 87d1fe5 to 9e14373 Compare January 15, 2024 14:19
@m90 m90 force-pushed the fr/50x-on-api-error branch from a49fa65 to 0116f75 Compare January 15, 2024 14:33
@m90
Copy link
Contributor Author

m90 commented Jan 15, 2024

@tarrow I refactored this so that it now caches any kind of response and also added "tests". Mind taking another look?

}
return $info;

return WBStackInfo::newFromJsonString($response, $requestDomain);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we still need to check what happens here; in the event this parsing fails and the static here returns a null we should build a WBStackLookupFailure; not quite sure how graceful or not failure would be in this case (since the logic in WBStackInfo is also very unpolished)

I tried this locally in a not super smart way as you can see at #411

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good catch, we shall add this still. Will do so right away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tarrow Added this in 75c7bd9

@m90 m90 force-pushed the fr/50x-on-api-error branch from b8928e9 to c6e9bbd Compare January 16, 2024 11:23
@m90 m90 force-pushed the fr/50x-on-api-error branch from c6e9bbd to 75c7bd9 Compare January 16, 2024 11:27
@@ -0,0 +1 @@
{"success":tr
Copy link
Contributor

Choose a reason for hiding this comment

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

Most realistic!

@m90 m90 merged commit 99b1625 into main Jan 16, 2024
9 checks passed
@m90 m90 deleted the fr/50x-on-api-error branch January 16, 2024 16:17
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.

2 participants