sdx-mailer-sdk 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +12 -0
- package/package.json +2 -4
- package/src/CourierMail.js +47 -0
- package/src/entities/CourierExceptionRequest.js +10 -0
- package/src/entities/CourierLink.js +8 -0
- package/src/entities/CourierRequest.js +13 -0
- package/src/entities/ServiceResponse.js +37 -0
- package/src/entities/WebServiceException.js +44 -0
- package/src/services/CourierService.js +32 -0
- package/src/utils/Commons.js +45 -0
- package/dist/index.js +0 -8
- package/src/CourierMail.ts +0 -49
- package/src/entities/CourierExceptionRequest.ts +0 -13
- package/src/entities/CourierLink.ts +0 -10
- package/src/entities/CourierRequest.ts +0 -10
- package/src/entities/ServiceResponse.ts +0 -40
- package/src/entities/WebServiceException.ts +0 -47
- package/src/index.d.ts +0 -5
- package/src/index.ts +0 -12
- package/src/services/CourierService.ts +0 -28
- package/src/utils/Commons.ts +0 -41
- package/tsconfig.json +0 -16
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const CourierMail = require('./src/CourierMail');
|
|
2
|
+
|
|
3
|
+
function createCourierRequest(title, subject, message, receiver, reply_mail, btn_label, btn_link) {
|
|
4
|
+
return CourierMail.createCourierRequest(title, subject, message, receiver, reply_mail, btn_label, btn_link)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function mockMail() {
|
|
9
|
+
return "Hello Mock!"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { createCourierRequest, mockMail };
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sdx-mailer-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A api rest sdx-mailer-sender sdk",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "index.js",
|
|
7
6
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
8
|
},
|
|
11
9
|
"repository": {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const CourierExceptionRequest = require("./entities/CourierExceptionRequest");
|
|
2
|
+
const CourierLink = require("./entities/CourierLink");
|
|
3
|
+
const CourierRequest = require("./entities/CourierRequest");
|
|
4
|
+
const WebServiceException = require("./entities/WebServiceException");
|
|
5
|
+
const CourierService = require("./services/CourierService");
|
|
6
|
+
const Commons = require("./utils/Commons");
|
|
7
|
+
|
|
8
|
+
class CourierMail {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.service = new CourierService();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
createCourierRequest(title, subject, message, receiver, reply_mail, btn_label, btn_link) {
|
|
14
|
+
let request = new CourierRequest();
|
|
15
|
+
request.title = title;
|
|
16
|
+
request.subject = subject;
|
|
17
|
+
request.message = message;
|
|
18
|
+
request.receiver = receiver;
|
|
19
|
+
request.reply_mail = reply_mail;
|
|
20
|
+
if (btn_label != null || btn_link != null) {
|
|
21
|
+
request.link = new CourierLink(btn_label, btn_link);
|
|
22
|
+
}
|
|
23
|
+
return request;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
createCourierExceptionRequest(error, detail, context) {
|
|
27
|
+
return new CourierExceptionRequest(error, detail, context);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async sendCourierMail(basicAuth, endpoint, tokenRQ, productId, isBasic) {
|
|
31
|
+
const url = endpoint + '/courier' + (isBasic ? '/basic' : '');
|
|
32
|
+
if (!Commons.validField(tokenRQ.trx)) {
|
|
33
|
+
throw WebServiceException.BAD_REQUEST("Request must be signed");
|
|
34
|
+
}
|
|
35
|
+
return await this.service.postMail(basicAuth, tokenRQ, url, 'sendContactMail', productId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async sendExceptionMail(basicAuth, endpoint, tokenRQ, productId) {
|
|
39
|
+
const url = endpoint + '/courier';
|
|
40
|
+
if (!Commons.validField(tokenRQ.trx)) {
|
|
41
|
+
throw WebServiceException.BAD_REQUEST("Request must be signed");
|
|
42
|
+
}
|
|
43
|
+
return await this.service.postMail(basicAuth, tokenRQ, url, 'sendContactMail', productId);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = CourierMail;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class ServiceResponse {
|
|
2
|
+
constructor(code, message) {
|
|
3
|
+
this.code = code;
|
|
4
|
+
this.message = message;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
static BAD_REQUEST() {
|
|
8
|
+
const result = new ServiceResponse(400, "Bad Request");
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static BUSINESS_ERROR() {
|
|
13
|
+
return new ServiceResponse(500, "Business Error");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static OK() {
|
|
17
|
+
return new ServiceResponse(200, "Ok");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static UNAUTHORIZED() {
|
|
21
|
+
return new ServiceResponse(401, "Unauthorized");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static NOT_FOUND() {
|
|
25
|
+
return new ServiceResponse(404, "Not Found");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static SERVICE_UNAVAILABLE() {
|
|
29
|
+
return new ServiceResponse(503, "Service Unavailable");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static METHOD_NOT_ALLOWED() {
|
|
33
|
+
return new ServiceResponse(405, "Method Not Allowed");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = ServiceResponse;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const ServiceResponse = require("./ServiceResponse");
|
|
2
|
+
|
|
3
|
+
class WebServiceException {
|
|
4
|
+
constructor(message, code, detail) {
|
|
5
|
+
this.message = message;
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.detail = detail;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static BAD_REQUEST(detail) {
|
|
11
|
+
return this.buildStaticClass(ServiceResponse.BAD_REQUEST(), detail);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static BUSINESS_ERROR(detail) {
|
|
15
|
+
return this.buildStaticClass(ServiceResponse.BUSINESS_ERROR(), detail);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static OK(detail) {
|
|
19
|
+
return this.buildStaticClass(ServiceResponse.OK(), detail);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static UNAUTHORIZED(detail) {
|
|
23
|
+
return this.buildStaticClass(ServiceResponse.UNAUTHORIZED(), detail);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static NOT_FOUND(detail) {
|
|
27
|
+
return this.buildStaticClass(ServiceResponse.NOT_FOUND(), detail);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static METHOD_NOT_ALLOWED(detail) {
|
|
31
|
+
return this.buildStaticClass(ServiceResponse.METHOD_NOT_ALLOWED(), detail);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static SERVICE_UNAVAILABLE(detail) {
|
|
35
|
+
return this.buildStaticClass(ServiceResponse.SERVICE_UNAVAILABLE(), detail);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static buildStaticClass(sr, detail) {
|
|
39
|
+
const result = new WebServiceException(sr.message, sr.code, detail);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = WebServiceException;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const Commons = require('../utils/Commons');
|
|
3
|
+
|
|
4
|
+
class CourierService {
|
|
5
|
+
async postMail(basicAuth, body, url, methodName, productId) {
|
|
6
|
+
try {
|
|
7
|
+
const res = await axios.post(url, body, this.buildOptions(basicAuth, true, productId));
|
|
8
|
+
return res.data;
|
|
9
|
+
} catch (err) {
|
|
10
|
+
throw Commons.buildWebServiceException(err, 'POST', methodName);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
buildOptions(basicAuth, fullView, productId) {
|
|
15
|
+
if (basicAuth !== null) {
|
|
16
|
+
return {
|
|
17
|
+
headers: {
|
|
18
|
+
'Authorization': basicAuth,
|
|
19
|
+
'product-id': productId,
|
|
20
|
+
'view': fullView ? 'full' : 'basic'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
headers: {
|
|
26
|
+
'product-id': productId
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = CourierService;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const WebServiceException = require('../entities/WebServiceException');
|
|
2
|
+
const ServiceResponse = require('../entities/ServiceResponse');
|
|
3
|
+
|
|
4
|
+
class Commons {
|
|
5
|
+
/**
|
|
6
|
+
* This method throws an exception when the call service request fail
|
|
7
|
+
* @param err
|
|
8
|
+
* @param verbMethod
|
|
9
|
+
* @param methodName
|
|
10
|
+
*/
|
|
11
|
+
static buildWebServiceException(err, verbMethod, methodName) {
|
|
12
|
+
let ws = null;
|
|
13
|
+
if (
|
|
14
|
+
this.validField(err) &&
|
|
15
|
+
this.validField(err.response) &&
|
|
16
|
+
this.validField(err.response.data) &&
|
|
17
|
+
this.validField(err.response.data.code)
|
|
18
|
+
) {
|
|
19
|
+
ws = new ServiceResponse(err.response.data.code, err.response.data.message);
|
|
20
|
+
ws.detail = err.response.data.detail;
|
|
21
|
+
}
|
|
22
|
+
if (ws != null) {
|
|
23
|
+
return WebServiceException.buildStaticClass(ws, this.buildDetailResponse(ws));
|
|
24
|
+
}
|
|
25
|
+
return WebServiceException.SERVICE_UNAVAILABLE('Error in ' + verbMethod + ' ' + methodName + ' service');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Detail builder for service response in throws, used by RequestServiceUtils
|
|
30
|
+
* @param ws
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
static buildDetailResponse(ws) {
|
|
34
|
+
if (this.validField(ws) && this.validField(ws.message)) {
|
|
35
|
+
return 'API_RESPONSE: ' + (this.validField(ws.detail) ? ws.detail : ws.message);
|
|
36
|
+
}
|
|
37
|
+
return 'API_RESPONSE: Without message';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static validField(arg) {
|
|
41
|
+
return arg != null && arg !== undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = Commons;
|
package/dist/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Agregar aca todas las clases principales para exportarlas directamente en los proyectos
|
|
2
|
-
* Replicar en index.d.ts
|
|
3
|
-
*/
|
|
4
|
-
export { default as CourierMail } from './CourierMail';
|
|
5
|
-
function mockMail() {
|
|
6
|
-
return 'Mock Success';
|
|
7
|
-
}
|
|
8
|
-
module.exports = { mockMail };
|
package/src/CourierMail.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import CourierExceptionRequest from "./entities/CourierExceptionRequest";
|
|
2
|
-
import CourierLink from "./entities/CourierLink";
|
|
3
|
-
import CourierRequest from "./entities/CourierRequest";
|
|
4
|
-
import WebServiceException from "./entities/WebServiceException";
|
|
5
|
-
import CourierService from "./services/CourierService";
|
|
6
|
-
import Commons from "./utils/Commons";
|
|
7
|
-
|
|
8
|
-
class CourierMail {
|
|
9
|
-
|
|
10
|
-
private service: CourierService;
|
|
11
|
-
|
|
12
|
-
constructor() {
|
|
13
|
-
this.service = new CourierService();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public createCourierRequest(title:string, subject:string,message:string,receiver:string,reply_mail:string,btn_label:string|null,btn_link:string|null):CourierRequest {
|
|
17
|
-
let request:CourierRequest = new CourierRequest();
|
|
18
|
-
request.title = title
|
|
19
|
-
request.subject = subject
|
|
20
|
-
request.message = message
|
|
21
|
-
request.receiver = receiver
|
|
22
|
-
request.reply_mail = reply_mail
|
|
23
|
-
if(btn_label != null || btn_link != null){
|
|
24
|
-
request.link = new CourierLink(btn_label,btn_link);
|
|
25
|
-
}
|
|
26
|
-
return request;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public createCourierExceptionRequest(error:string, detail:string,context:string|null):CourierExceptionRequest {
|
|
30
|
-
return new CourierExceptionRequest(error,detail,context);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async sendCourierMail(basicAuth:string|null,endpoint:string,tokenRQ:any,productId:number,isBasic:boolean) {
|
|
34
|
-
const url = endpoint + '/courier' + ((isBasic)? '/basic' : '');
|
|
35
|
-
if(!Commons.validField(tokenRQ.trx)){
|
|
36
|
-
throw WebServiceException.BAD_REQUEST("Request must be signed")
|
|
37
|
-
}
|
|
38
|
-
return await this.service.postMail(basicAuth, tokenRQ, url, 'sendContactMail',productId);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public async sendExceptionMail(basicAuth:string|null,endpoint:string,tokenRQ:any,productId:number) {
|
|
42
|
-
const url = endpoint + '/courier';
|
|
43
|
-
if(!Commons.validField(tokenRQ.trx)){
|
|
44
|
-
throw WebServiceException.BAD_REQUEST("Request must be signed")
|
|
45
|
-
}
|
|
46
|
-
return await this.service.postMail(basicAuth, tokenRQ, url, 'sendContactMail',productId);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export default CourierMail;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default class CourierExceptionRequest {
|
|
3
|
-
|
|
4
|
-
constructor(error:string,detail:string,context:string|null){
|
|
5
|
-
this.error = error
|
|
6
|
-
this.detail = detail
|
|
7
|
-
this.context = context
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public error: string;
|
|
11
|
-
public detail: string|null;
|
|
12
|
-
public context: string|null;
|
|
13
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default class ServiceResponse {
|
|
3
|
-
public code: number
|
|
4
|
-
public message: string
|
|
5
|
-
public detail: string | undefined
|
|
6
|
-
|
|
7
|
-
constructor(code: number, message: string) {
|
|
8
|
-
this.code = code
|
|
9
|
-
this.message = message
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public static BAD_REQUEST(): ServiceResponse {
|
|
13
|
-
var result = new ServiceResponse(400, "Bad Request")
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public static BUSINESS_ERROR(): ServiceResponse {
|
|
18
|
-
return new ServiceResponse(500, "Business Error")
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public static OK(): ServiceResponse {
|
|
22
|
-
return new ServiceResponse(200, "Ok")
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static UNAUTHORIZED(): ServiceResponse {
|
|
26
|
-
return new ServiceResponse(401, "Unauthorized")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public static NOT_FOUND(): ServiceResponse {
|
|
30
|
-
return new ServiceResponse(404, "Not Found")
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public static SERVICE_UNAVAILABLE(): ServiceResponse {
|
|
34
|
-
return new ServiceResponse(503, "Service Unavailable")
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public static METHOD_NOT_ALLOWED(): ServiceResponse {
|
|
38
|
-
return new ServiceResponse(405, "Method Not Allowed")
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import ServiceResponse from "./ServiceResponse";
|
|
2
|
-
|
|
3
|
-
export default class WebServiceException {
|
|
4
|
-
public code: number;
|
|
5
|
-
public detail: string;
|
|
6
|
-
public message: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(message: string, code: number, detail: string) {
|
|
10
|
-
this.message = message;
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.detail = detail;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public static BAD_REQUEST(detail: string): WebServiceException {
|
|
16
|
-
return this.buildStaticClass(ServiceResponse.BAD_REQUEST(), detail);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public static BUSINESS_ERROR(detail: string): WebServiceException {
|
|
20
|
-
return this.buildStaticClass(ServiceResponse.BUSINESS_ERROR(), detail);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public static OK(detail: string): WebServiceException {
|
|
24
|
-
return this.buildStaticClass(ServiceResponse.OK(), detail);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public static UNAUTHORIZED(detail: string): WebServiceException {
|
|
28
|
-
return this.buildStaticClass(ServiceResponse.UNAUTHORIZED(), detail);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public static NOT_FOUND(detail: string): WebServiceException {
|
|
32
|
-
return this.buildStaticClass(ServiceResponse.NOT_FOUND(), detail);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static METHOD_NOT_ALLOWED(detail: string): WebServiceException {
|
|
36
|
-
return this.buildStaticClass(ServiceResponse.METHOD_NOT_ALLOWED(), detail);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public static SERVICE_UNAVAILABLE(detail: string): WebServiceException {
|
|
40
|
-
return this.buildStaticClass(ServiceResponse.SERVICE_UNAVAILABLE(), detail);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static buildStaticClass(sr: ServiceResponse, detail: string): WebServiceException {
|
|
44
|
-
var result = new WebServiceException(sr.message, sr.code, detail)
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/index.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** Agregar aca todas las clases principales para exportarlas directamente en los proyectos
|
|
2
|
-
* Replicar en index.d.ts
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { default as CourierMail } from './CourierMail';
|
|
6
|
-
|
|
7
|
-
function mockMail() {
|
|
8
|
-
return 'Mock Success';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
module.exports = { mockMail };
|
|
12
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import Commons from '../utils/Commons';
|
|
3
|
-
|
|
4
|
-
export default class CourierService {
|
|
5
|
-
public async postMail(basicAuth: string | null, body: any, url: string, methodName: string, productId: number) {
|
|
6
|
-
const res = await axios.post(url, body, this.buildOptions(basicAuth, true,productId)).catch(function (err:any) {
|
|
7
|
-
throw Commons.buildWebServiceException(err, 'POST', methodName);
|
|
8
|
-
});
|
|
9
|
-
return res.data;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
private buildOptions(basicAuth: string | null, fullView: boolean, productId: number) {
|
|
13
|
-
if (basicAuth != null) {
|
|
14
|
-
return {
|
|
15
|
-
headers: {
|
|
16
|
-
'Authorization': basicAuth,
|
|
17
|
-
'product-id': productId,
|
|
18
|
-
'view': (fullView) ? 'full' : 'basic'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
headers: {
|
|
24
|
-
'product-id': productId
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/utils/Commons.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import WebServiceException from '../entities/WebServiceException';
|
|
2
|
-
import ServiceResponse from '../entities/ServiceResponse';
|
|
3
|
-
|
|
4
|
-
export default class Commons {
|
|
5
|
-
/**
|
|
6
|
-
* This method throws an exception when the call service request fail
|
|
7
|
-
* @param err
|
|
8
|
-
* @param verbMethod
|
|
9
|
-
* @param methodName
|
|
10
|
-
*/
|
|
11
|
-
static buildWebServiceException(err: any, verbMethod: string, methodName: string): WebServiceException {
|
|
12
|
-
var ws: any = null
|
|
13
|
-
if (this.validField(err)
|
|
14
|
-
&& this.validField(err.response)
|
|
15
|
-
&& this.validField(err.response.data)
|
|
16
|
-
&& this.validField(err.response.data.code)) {
|
|
17
|
-
ws = new ServiceResponse(err.response.data.code, err.response.data.message)
|
|
18
|
-
ws.detail = err.response.data.detail
|
|
19
|
-
}
|
|
20
|
-
if (ws != null) {
|
|
21
|
-
return WebServiceException.buildStaticClass(ws, this.buildDetailResponse(ws))
|
|
22
|
-
}
|
|
23
|
-
return WebServiceException.SERVICE_UNAVAILABLE('Error in ' + verbMethod + ' ' + methodName + ' service')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Detail builder for service response in throws, used by RequestServiceUtils
|
|
28
|
-
* @param ws
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
static buildDetailResponse(ws: any): string {
|
|
32
|
-
if (Commons.validField(ws) && Commons.validField(ws.message)) {
|
|
33
|
-
return 'API_RESPONSE: ' + ((Commons.validField(ws.detail)) ? ws.detail : ws.message);
|
|
34
|
-
}
|
|
35
|
-
return 'API_RESPONSE: Without message'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static validField(arg: any) {
|
|
39
|
-
return arg != null && arg != undefined
|
|
40
|
-
}
|
|
41
|
-
}
|
package/tsconfig.json
DELETED