ramda / ramda.github.io

:ram: :globe_with_meridians: Documentation for Ramda.js
http://ramdajs.com
57 stars 72 forks source link

Trying to create REPL share links with large amounts of code fails. #174

Open jlengstorf opened 7 years ago

jlengstorf commented 7 years ago

In the REPL, trying to create a share link with a large code sample will fail. This happens because Google's URL shortener won't accept URLs over a certain length and returns a 400 error.

The shortener seems to start throwing errors at 4,096 characters.

A possible solution would be an error handler for 400 errors from Google that checks the URL length and offers a helpful error message:

Cannot create a share link for URLs over 4,096 characters in length. Please reduce the size of your sample code to share.

Alternatively, an event handler on the function that changes the URL could do a quick check for length and disable the share button with a title message explaining that the current code snippet is too long to be shared.

buzzdecafe commented 7 years ago

Thanks; I prefer the former; we should trap the error; then if google changes what length they like, we don't have to chase them.

jlengstorf commented 7 years ago

@buzzdecafe It looks like the REPL has a hard-coded link to the master bundle, so I'm not sure how to test this locally, but I think the following in repl/lib/js/googl.js:40 would be a quick-and-dirty fix to at least give some feedback:

  const getShortUrl = R.map(R.compose(setValue, R.prop('id')));
+ const getErrorMessage = R.map(setValue, R.path(['error', 'message']));
+ const handleResponse = R.ifElse(
+   R.has('error'),
+   getErrorMessage,
+   getShortUrl,
+ );

  const futureXhr = getResponse(apiUrl);

- export default () => makeShortUrlBtn.addEventListener('click', () => futureXhr.fork(error, getShortUrl));
+ export default () => makeShortUrlBtn.addEventListener('click', () => futureXhr.fork(error, handleResponse));

If there's a way to test the REPL locally that I'm missing, let me know and I'll send a proper PR.

buzzdecafe commented 7 years ago

repl has its own repo: https://github.com/ramda/repl

it's been a while since i've done any work in there, so i don't recall how to build/run locally.

ping @craigdallimore @MattMS

MattMS commented 7 years ago

It's been a while since I looked at the REPL integration with the site, so I'll go through it again now and see how it's all setup.

MattMS commented 7 years ago

It seems like the REPL code is still in the site repo, so the new REPL code hasn't been integrated yet. I'm not sure of the current state of the REPL code (in either repo), so I'll try and make some time tomorrow to check it out (it's a bit late here now).