Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

dataworld: improve error message #394

Merged
merged 2 commits into from
Mar 7, 2018

Conversation

n-riesco
Copy link
Contributor

@n-riesco n-riesco commented Mar 2, 2018

@kndungu @rflprr Since you are familiar with the code, would you like to review this PR?

  • data.world: send error message of failed queries.

  • Preview: repect line breaks in error messages and use mono-space font.

Closes #389

screenshot from 2018-03-02 17-49-55

Copy link
Contributor

@kndungu kndungu left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @n-riesco!

Just two minor comments:

@@ -88,6 +88,11 @@ export function query(queryString, connection) {
body: params
})
.then(res => {
if (res.status !== 200) {
return res.text().then(body => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately not all error messages are returned as text, some come in the form of an error object.

For example, 401s produce the following response:

{ "code": 401, "request": "06d583b7-afbf-48ca-b1b8-961ed0b092a0", "message": "Unauthorized" }

Displaying the entire object is unnecessary since only the content of message is useful to the user.

We could replace this bit of code with:

if (res.status !== 200) {
  return res.text().then(body => {
    try {
      const errorObject = JSON.parse(body);
      throw new Error(errorObject.message);
    } catch (err) {
      if (err.name === 'SyntaxError') {
        throw new Error(body);
      }
      
      throw new Error(err.message);
    }
  });
}

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've handled this in Preview.react.js so that other connectors benefit from this PR.

Copy link
Contributor

@kndungu kndungu Mar 7, 2018

Choose a reason for hiding this comment

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

Agreed, the changes in Preview.react.js allow all connectors to display a custom error message instead of simply "stringifying" the error thrown.

The change I'm suggesting has to do with the custom error that the data.world connector throws.

When the response from the API is a string it will be displayed as is, e.g.

When it is a 400 the response from the API is a string specifying the specific problem (e.g. '(' expected but 'BADSELECT' found... )

But when the response is an object the entire object is shown, e.g.

When it is a 401 the response from the API is an object that is overly verbose ({ "code": 401, "request": "06d583b7-afbf-48ca-b1b8-961ed0b092a0", "message": "Unauthorized" })

As it currently stands this entire object will be displayed to the user, the change I'm proposing will result in only the contents of the message attribute being displayed to the user i.e. Unauthorized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kndungu My bad! Your first explanation was clear enough.

I've fixed this in 11950d1 . I've also tested it manually.

Please, let me know if it looks OK to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

@n-riesco no worries!

Yes it does! More elegant than my suggested fix :shipit:

let successMsg = '';

let errorMsg = '';
function setErrorMsg(error) {
if (error && error.content && error.content.error && error.content.error.message) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To be more succinct we could go with:

try {
  errorMsg = error.content.error.message;
} catch(err) {
  errorMsg = JSON.stringify(error);
} finally {
  errorMsg = String(errorMsg).trim();
}

* data.world: send error message of failed queries.

* Preview: repect line breaks in error messages and use mono-space font.

Closes plotly#389
@n-riesco n-riesco force-pushed the dataworld/improve-error-message branch from 18b120e to 4b203a2 Compare March 7, 2018 15:33
@n-riesco
Copy link
Contributor Author

n-riesco commented Mar 7, 2018

@kndungu I've updated the PR using your comments and rebased it against master. I'll merge it, if you're happy with the latest changes.

@n-riesco n-riesco merged commit 169f245 into plotly:master Mar 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants