Skip to content

Commit 85ec9e5

Browse files
authored
Merge pull request #62 from Luidog/login-bugfix
Login fix
2 parents 0563b1d + 77671de commit 85ec9e5

File tree

5 files changed

+64
-54
lines changed

5 files changed

+64
-54
lines changed

package-lock.json

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@
3939
},
4040
"homepage": "https://github.com/Luidog/fms-api-client",
4141
"dependencies": {
42-
"axios": "^0.19.0",
42+
"axios": "^0.19.1",
4343
"axios-cookiejar-support": "^0.5.1",
4444
"form-data": "^3.0.0",
4545
"into-stream": "^5.1.1",
4646
"lodash": "^4.17.15",
4747
"marpat": "^3.0.0",
48-
"mime-types": "^2.1.25",
48+
"mime-types": "^2.1.26",
4949
"moment": "^2.24.0",
5050
"object-sizeof": "^1.5.2",
5151
"prettysize": "^2.0.0",
52-
"snyk": "^1.272.0",
52+
"snyk": "^1.278.1",
5353
"stream-to-array": "^2.3.0",
5454
"tough-cookie": "^3.0.1",
5555
"uuid": "^3.3.3"
@@ -66,7 +66,7 @@
6666
"eslint-config-prettier": "^6.9.0",
6767
"eslint-plugin-prettier": "^3.1.2",
6868
"fs-extra": "^8.1.0",
69-
"handlebars": "^4.5.3",
69+
"handlebars": "^4.7.2",
7070
"http-proxy": "^1.18.0",
7171
"jsdoc": "^3.6.3",
7272
"jsdoc-to-markdown": "^5.0.3",
@@ -81,7 +81,7 @@
8181
"mos-plugin-snippet": "^2.1.3",
8282
"nyc": "^15.0.0",
8383
"prettier": "^1.19.1",
84-
"sinon": "^8.0.2",
84+
"sinon": "^8.0.4",
8585
"varium": "^2.0.6"
8686
},
8787
"snyk": true

src/services/container.service.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
'use strict';
22

3+
const axios = require('axios');
4+
const axiosCookieJarSupport = require('axios-cookiejar-support').default;
35
const fs = require('fs');
46
const path = require('path');
57
const toArray = require('stream-to-array');
68
const { CookieJar } = require('tough-cookie');
79
const mime = require('mime-types');
810
const uuidv4 = require('uuid/v4');
911
const _ = require('lodash');
10-
const { instance } = require('./request.service');
12+
const { interceptResponse } = require('./request.service')
13+
14+
const instance = axios.create();
15+
16+
axiosCookieJarSupport(instance);
1117

1218
/**
1319
* @class Container Service
@@ -19,7 +25,7 @@ const { instance } = require('./request.service');
1925
* @param {Any} error We publishing error.
2026
*/
2127
instance.interceptors.response.use(
22-
response => response,
28+
response => interceptResponse(response),
2329
error => handleError(error)
2430
);
2531

src/services/request.service.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ axiosCookieJarSupport(instance);
2424
const interceptError = error => {
2525
if (error.code) {
2626
return Promise.reject({ code: error.code, message: error.message });
27-
} else if (
28-
error.response.status === 502 ||
29-
typeof error.response.data !== 'object'
30-
) {
31-
return Promise.reject({
32-
message: 'The Data API is currently unavailable',
33-
code: '1630'
34-
});
3527
} else if (
3628
error.response.status === 400 &&
3729
error.request.path.includes('RCType=EmbeddedRCFileProcessor')
@@ -40,6 +32,15 @@ const interceptError = error => {
4032
message: 'FileMaker WPE rejected the request',
4133
code: '9'
4234
});
35+
} else if (
36+
error.response.status === 502 ||
37+
typeof error.response.data !== 'object' ||
38+
!error.response.data.messages
39+
) {
40+
return Promise.reject({
41+
message: 'The Data API is currently unavailable',
42+
code: '1630'
43+
});
4344
} else {
4445
return Promise.reject(error.response.data.messages[0]);
4546
}
@@ -77,5 +78,6 @@ instance.interceptors.response.use(
7778
);
7879

7980
module.exports = {
80-
instance
81+
instance,
82+
interceptResponse
8183
};

test/authentication.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ describe('Authentication Capabilities', () => {
143143
.catch(error => error)
144144
)
145145
.to.eventually.be.an('object')
146-
.that.has.all.keys('code', 'message');
146+
.that.has.all.keys('code', 'message')
147+
.and.property('code')
148+
.to.equal('212');
147149
});
148150

149151
it('should reject if it can not create a new data api session', () => {

0 commit comments

Comments
 (0)