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

Make sure we handle failures in mediaproxied requests gracefully #505

Merged
merged 6 commits into from
Sep 5, 2024

Conversation

tadzik
Copy link
Contributor

@tadzik tadzik commented Sep 5, 2024

Fixes matrix-org/matrix-appservice-irc#1816 blowing up the whole bridge when the request fails for any reason.

@tadzik tadzik requested a review from a team as a code owner September 5, 2024 09:05
Copy link
Contributor

@Half-Shot Half-Shot left a comment

Choose a reason for hiding this comment

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

We can do a bit better :)

}, (getRes) => {
try {
const { statusCode } = res;
res.setHeader('content-disposition', getRes.headers['content-disposition'] as string);
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest something like:

            if (getRes.headers["content-disposition"]) {
                res.setHeader("content-disposition", getRes.headers["content-disposition"] as string);
            }
            if (getRes.headers["content-type"]) {
                res.setHeader("content-type", getRes.headers["content-type"] as string);
            }
            if (getRes.headers["content-length"]) {
                res.setHeader("content-length", getRes.headers["content-length"] as string);
            }

which prevent the undefined values from throwing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And now we can drop type casts too. The compiler was right all along :)

@tadzik tadzik merged commit 4792f07 into develop Sep 5, 2024
8 checks passed
@tadzik tadzik deleted the tadzik/improve-mediaproxy-error-handling branch September 5, 2024 13:57
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.

MediaProxy Not Working
2 participants