I have tested my code for the URL shortener using different URLs (Wrong and Correct URLs) and they all work well. However, on submission of my code link to FCC, it gives an error.
see the test that gives the error below.
If you pass an invalid URL that doesn't follow the valid
http://www.example.com
format, the JSON response will contain
{ error: 'invalid url' }
// tests completed
At first, I thought it was case sensitive and the error output had to be exactly { error: 'invalid url' }. I tried setting my JSON error output to all lower case and the FCC error continued.
I made the output { error: 'invalid URL' } and { error: 'Invalid URL' } still no success.
During my URL validation, I had set 2 error messages.
If URL does not follow the http://example.com format, you get { error: 'invalid URL' }
if the URL hostname does not map to a valid address, you get { error: 'invalid Hostname' }
I thought this was the cause of the FCC Test Failure and had set both errors to output { error: 'invalid url' } yet the test still failed.
I will appreciate it if I am advised on a way forward on this issue.
When I run the fCC tests against your project, I get this error
frame-runner.js:98 TypeError: Cannot read property 'toLowerCase' of undefined
at eval
in the browser console, which means the tests are getting an empty response. That’s probably because you’re sending a status of 400, which the tests interpret as failure. So you would need to remove that despite it making sense for a real app.
I can’t get glitch to fork and run right now, but you should log all your inputs and responses to your isValidUrl function in your URL controller because I believe it has the same problems I discussed here. The fCC tests don’t send a bare URL; they have some URL parameters tacked on as well that dns.lookup() cowardly refuses to handle.
I did not even remember that the browser has a console. I guess I have been trying to fix this issue for days now and I am already out of ideas.
I have taken out the status code (400) associated with the isValidUrl in my controller. However, the error is still showing up with pride.
I already set short_url to store itself on the database. If it does not exist (as in the case of a first POST request to shorten a URL) it creates itself and still gets stored on the database.
I am upcoming so, even if I make series of logs, I may end up not being able to decipher which of the information will be useful to fix my problem. I did a few console.log() though, particularly in the isValidUrl function. This feels like where the issue might be coming from. Nothing colourful yet after me Logging
I am still struggling with the issue.
From the browser error that you shared and to my understanding, I can interpret it to mean that there is a missing return value and hence the undefined. I am not sure if I can tell where this is coming from.
Thank you for your response.
Let me know if you find any other corrections that I can make, to get me running.