Skip to content

Handle Medium request failures - #66

Open
dajiaohuang wants to merge 2 commits into
djadmin:masterfrom
dajiaohuang:fix-request-errors
Open

dajiaohuang wants to merge 2 commits into
djadmin:masterfrom
dajiaohuang:fix-request-errors

Conversation

@dajiaohuang

Copy link
Copy Markdown

Problem

When the request callback reports a transport error, res is absent. The existing callback dereferenced res.statusCode, causing an uncaught TypeError and leaving the getStories promise unresolved. Other non-200/non-404 responses also left the promise pending.

Change

Propagate request and HTTP errors through the existing callback/promise path, so callers receive a rejected promise instead of a crash or hang. Successful response processing is unchanged.

Validation

  • node --check lib/post.js
  • git diff --check
  • Mocked request callbacks for synthetic network error, HTTP 503, and HTTP 404 each produced a rejected promise with the expected error.
  • No dependency installation or real Medium request was made; repository has no declared test script.

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.

1 participant