return undefined response item

This commit is contained in:
Jilling Kingma
2022-09-19 14:18:46 +02:00
parent e36af2f7c7
commit 692a133058

View File

@@ -32,6 +32,8 @@ import {
TerminalApiSecuredResponse TerminalApiSecuredResponse
} from "../typings/terminal/models"; } from "../typings/terminal/models";
import NexoCryptoException from "./exception/nexoCryptoException"; import NexoCryptoException from "./exception/nexoCryptoException";
import HttpClientException from "../httpClient/httpClientException";
import apiException from "./exception/apiException";
class TerminalLocalAPI extends ApiKeyAuthenticatedService { class TerminalLocalAPI extends ApiKeyAuthenticatedService {
private readonly localRequest: LocalRequest; private readonly localRequest: LocalRequest;
@@ -58,16 +60,13 @@ class TerminalLocalAPI extends ApiKeyAuthenticatedService {
SaleToPOIRequest: saleToPoiSecuredMessage, SaleToPOIRequest: saleToPoiSecuredMessage,
}, "TerminalApiSecuredRequest"); }, "TerminalApiSecuredRequest");
const jsonResponse = await getJsonResponse<TerminalApiSecuredRequest, TerminalApiResponse>( // Catch Exceptions and an empty jsonResponse (i.e. Abort Request)
this.localRequest,
securedPaymentRequest
);
console.log("jsonresponse type" + typeof jsonResponse);
console.log(jsonResponse);
// Catch an empty jsonResponse (i.e. Abort Request)
try { try {
const jsonResponse = await getJsonResponse<TerminalApiSecuredRequest, TerminalApiResponse>(
this.localRequest,
securedPaymentRequest
);
const terminalApiSecuredResponse: TerminalApiSecuredResponse = const terminalApiSecuredResponse: TerminalApiSecuredResponse =
ObjectSerializer.deserialize(jsonResponse, "TerminalApiSecuredResponse"); ObjectSerializer.deserialize(jsonResponse, "TerminalApiSecuredResponse");
@@ -78,11 +77,10 @@ class TerminalLocalAPI extends ApiKeyAuthenticatedService {
return ObjectSerializer.deserialize(JSON.parse(response), "TerminalApiResponse"); return ObjectSerializer.deserialize(JSON.parse(response), "TerminalApiResponse");
} catch (e) { } catch (e) {
if(e instanceof NexoCryptoException){ if(e instanceof NexoCryptoException || e instanceof HttpClientException || e instanceof apiException) {
throw e; throw e;
} else { } else {
const requestType = terminalApiRequest.SaleToPOIRequest.MessageHeader.MessageCategory; return new TerminalApiResponse();
throw new Error(`Request of type ${requestType} has no response!`);
} }
} }
} }