Skip to content

Commit

Permalink
fix(api-core): avFiles error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Christie Baker authored and Christie Baker committed Mar 23, 2018
1 parent 68ce3b2 commit 3dd5392
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/api-core/src/ms.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@ export default class AvMicroservice extends AvApi {
.replace(/[/]+/g, '/')
.replace(/\/$/, '');
}

// make request to http
request(config, afterResponse) {
return this.http(config)
.then(response => this.onResponse(response, afterResponse))
.catch(error => {
let response;
if (error) {
response = error;
response.error = true;
}
return afterResponse ? afterResponse(response) : response;
});
}
}
2 changes: 1 addition & 1 deletion packages/api-core/src/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Upload a file to a bucket in the vault

#### `uploadFile(data, config)`
Method to upload a file. `data` contains FormData elements with a key of either `reference` (if pointed to an existing file) or `filedata` (if uploading a new file)
`config` should contain `customerId` and `id` (the bucketId)
`config` should contain `customerId`, `id` (the bucketId), and `clientId`


### AvSettings
Expand Down
6 changes: 5 additions & 1 deletion packages/api-core/src/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default class AvFiles extends AvMicroservice {
name: 'core/vault/upload/v1',
headers: {
'Content-Type': undefined,
'X-App-Context': 'ecs-qa-app-context',
},
},
config
Expand All @@ -21,8 +20,13 @@ export default class AvFiles extends AvMicroservice {
}

uploadFile(data, config) {
if (!config.customerId || !config.clientId) {
throw Error('[config.customerId] and [config.clientId] must be defined');
}
config = this.config(config);
config.headers['X-Availity-Customer-ID'] = config.customerId;
config.headers['X-Client-ID'] = config.clientId;

return this.create(data, config);
}
}
2 changes: 2 additions & 0 deletions packages/api-core/src/resources/tests/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const mockMerge = jest.fn((...args) => Object.assign(...args));

const mockConfig = {
id: '123',
clientId: '123-456',
customerId: '1194',
};

describe('AvFiles', () => {
Expand Down

0 comments on commit 3dd5392

Please sign in to comment.