Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(BBD 842): Improper error handling in api-javascript#81

Merged
effervescentia merged 27 commits into
developgroupby/api-javascript:developfrom
BBD-842groupby/api-javascript:BBD-842Copy head branch name to clipboard
Nov 15, 2017
Merged

feat(BBD 842): Improper error handling in api-javascript#81
effervescentia merged 27 commits into
developgroupby/api-javascript:developfrom
BBD-842groupby/api-javascript:BBD-842Copy head branch name to clipboard

Conversation

@Filip-F

@Filip-F Filip-F commented Nov 15, 2017

Copy link
Copy Markdown
Contributor

Labeling feat since we're also switching from axios to fetch-ponyfill.

@codecov-io

codecov-io commented Nov 15, 2017

Copy link
Copy Markdown

Codecov Report

Merging #81 into develop will increase coverage by 4.08%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #81      +/-   ##
===========================================
+ Coverage    95.08%   99.17%   +4.08%     
===========================================
  Files            3        3              
  Lines          224      241      +17     
  Branches        19       21       +2     
===========================================
+ Hits           213      239      +26     
+ Misses           1        0       -1     
+ Partials        10        2       -8
Impacted Files Coverage Δ
src/core/bridge.ts 100% <100%> (+5.55%) ⬆️
src/core/query.ts 98.42% <0%> (+3.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 528ac3d...acd83a8. Read the comment docs.

@Filip-F Filip-F requested a review from groupby-ops November 15, 2017 17:50
jatkinson10
jatkinson10 previously approved these changes Nov 15, 2017

@jatkinson10 jatkinson10 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I’m good with this. Can i get a quick demo?

Comment thread src/core/bridge.ts Outdated
@@ -1,4 +1,5 @@
import * as axios from 'axios';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

delet this

Comment thread test/unit/core/bridge.ts Outdated

expect(bridge.config).to.eql({
timeout: 4000
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

object can be one line

Comment thread test/unit/core/bridge.ts
_id: id,
_u: url,
_t: title,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

object can be one line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Too many keys for a one line object.

Comment thread test/unit/core/bridge.ts Outdated
});
bridge.search(new Query('skirts')).catch((err) => {
expect(err).to.be.an.instanceof(BridgeTimeout);
expect(err.message).to.eql('Timed out in 1500 ms');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

may want to comment that this is the default timeout value

zfcb
zfcb previously approved these changes Nov 15, 2017

@effervescentia effervescentia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some changes

Comment thread src/core/bridge.ts Outdated

constructor(config: BridgeConfig) {
this.config = Object.assign({}, DEFAULT_CONFIG, config);
this.fetch = fetchPonyfill().fetch;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a reason we set this in the constructor rather than with the instance variable declaration?

class AbstractBridge {
  fetch: fetchPonyfill = fetchPonyfill().fetch;
}

Comment thread src/core/bridge.ts Outdated
export abstract class AbstractBridge {

config: BridgeConfig;
fetch: fetchPonyfill;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this the correct type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what the correct type is here, this seemed most correct to me, is there a better one?

Comment thread src/core/bridge.ts Outdated
export class BridgeTimeout extends Error {
constructor (err: string) {
super(err);
Object.setPrototypeOf(this, BridgeTimeout.prototype);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we calling this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tests were failing before when I didn't have it. Now they're not. I guess I'll just remove it.

Comment thread src/core/bridge.ts Outdated
};
return axios(options)
.then((res) => res.data)
const timeoutPromise = () =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rather than make this a function created every time fireRequest() is called, let's make this a function at the top level called createTimeoutPromise() that accepts a timeout parameter

Comment thread src/core/bridge.ts Outdated
});

const params = qs.stringify(queryParams);
url = params ? url + '?' + params : url;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's use a template literal here

`${url}?${params}`

Comment thread src/core/bridge.ts Outdated

const params = qs.stringify(queryParams);
url = params ? url + '?' + params : url;
const response = Promise.race([this.fetch(url, options), timeoutPromise()])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this solution 👍 very elegant

Comment thread src/core/bridge.ts Outdated
return res.json();
} else {
return res.json().then((err) => {
throw {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should throw another custom Error type here for clarity

Comment thread src/core/bridge.ts
export class BridgeError extends Error {
constructor (statusText: string, public status: number, public data: any) {
super(statusText);
Object.setPrototypeOf(this, BridgeError.prototype);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We need this one or else the prototype is going to be the same as Error, and the getter I defined lower down won't work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@effervescentia effervescentia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good 👍

Comment thread src/core/bridge.ts
export class BridgeError extends Error {
constructor (statusText: string, public status: number, public data: any) {
super(statusText);
Object.setPrototypeOf(this, BridgeError.prototype);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@effervescentia effervescentia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

found a couple of changes

Comment thread src/core/bridge.ts Outdated

const params = qs.stringify(queryParams);
url = params ? `${url}?${params}` : url;
const response = Promise.race([this.fetch(url, options), createTimeoutPromise(this.config.timeout)])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can just be returned directly

Comment thread src/core/bridge.ts

export class BridgeTimeout extends Error {
constructor (err: string) {
super(err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we lost overall coverage because of these lines, can we add a simple test to this

Comment thread src/core/bridge.ts

export class BridgeError extends Error {
constructor (statusText: string, public status: number, public data: any) {
super(statusText);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we lost overall coverage because of these lines, can we add a simple test to this

Comment thread src/core/bridge.ts
}

get statusText() {
return this.message;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we lost overall coverage because of these lines, can we add a simple test to this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops forgot to commit it last time, done.

@effervescentia effervescentia merged commit 2272c54 into develop Nov 15, 2017
@effervescentia effervescentia deleted the BBD-842 branch November 15, 2017 20:36
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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.