src: add error_msg to create pretty pcsc errors
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "cardreader.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
@@ -334,7 +335,7 @@ void CardReader::HandleReaderStatusChange(uv_async_t *handle, int status) {
|
||||
|
||||
NanCallback(NanNew(async_baton->callback)).Call(argc, argv);
|
||||
} else {
|
||||
Local<Value> err = NanError(pcsc_stringify_error(ar->result));
|
||||
Local<Value> err = NanError(error_msg("SCardGetStatusChange", ar->result).c_str());
|
||||
// Prepare the parameters for the callback function.
|
||||
const unsigned argc = 1;
|
||||
Handle<Value> argv[argc] = { err };
|
||||
@@ -423,7 +424,7 @@ void CardReader::AfterConnect(uv_work_t* req, int status) {
|
||||
ConnectResult *cr = static_cast<ConnectResult*>(baton->result);
|
||||
|
||||
if (cr->result) {
|
||||
Local<Value> err = NanError(pcsc_stringify_error(cr->result));
|
||||
Local<Value> err = NanError(error_msg("SCardConnect", cr->result).c_str());
|
||||
// Prepare the parameters for the callback function.
|
||||
const unsigned argc = 1;
|
||||
Handle<Value> argv[argc] = { err };
|
||||
@@ -477,7 +478,7 @@ void CardReader::AfterDisconnect(uv_work_t* req, int status) {
|
||||
LONG* result = reinterpret_cast<LONG*>(baton->result);
|
||||
|
||||
if (*result) {
|
||||
Local<Value> err = NanError(pcsc_stringify_error(*result));
|
||||
Local<Value> err = NanError(error_msg("SCardDisconnect", *result).c_str());
|
||||
|
||||
// Prepare the parameters for the callback function.
|
||||
const unsigned argc = 1;
|
||||
@@ -538,7 +539,7 @@ void CardReader::AfterTransmit(uv_work_t* req, int status) {
|
||||
TransmitResult *tr = static_cast<TransmitResult*>(baton->result);
|
||||
|
||||
if (tr->result) {
|
||||
Local<Value> err = NanError(pcsc_stringify_error(tr->result));
|
||||
Local<Value> err = NanError(error_msg("SCardTransmit", tr->result).c_str());
|
||||
|
||||
// Prepare the parameters for the callback function.
|
||||
const unsigned argc = 1;
|
||||
@@ -602,7 +603,7 @@ void CardReader::AfterControl(uv_work_t* req, int status) {
|
||||
ControlResult *cr = static_cast<ControlResult*>(baton->result);
|
||||
|
||||
if (cr->result) {
|
||||
Local<Value> err = NanError(pcsc_stringify_error(cr->result));
|
||||
Local<Value> err = NanError(error_msg("SCardControl", cr->result).c_str());
|
||||
|
||||
// Prepare the parameters for the callback function.
|
||||
const unsigned argc = 1;
|
||||
|
||||
18
src/common.h
Normal file
18
src/common.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#define ERR_MSG_MAX_LEN 512
|
||||
|
||||
namespace {
|
||||
std::string error_msg(const char* method, LONG result) {
|
||||
char msg[ERR_MSG_MAX_LEN];
|
||||
snprintf(msg,
|
||||
ERR_MSG_MAX_LEN,
|
||||
"%s error: %s(0x%.8lx)",
|
||||
method,
|
||||
pcsc_stringify_error(result), result);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* COMMON_H */
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "pcsclite.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
@@ -28,7 +29,7 @@ PCSCLite::PCSCLite(): m_card_context(NULL),
|
||||
NULL,
|
||||
&m_card_context);
|
||||
if (result != SCARD_S_SUCCESS) {
|
||||
NanThrowError(pcsc_stringify_error(result));
|
||||
NanThrowError(error_msg("SCardEstablishContext", result).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ void PCSCLite::HandleReaderStatusChange(uv_async_t *handle, int status) {
|
||||
|
||||
NanCallback(NanNew(async_baton->callback)).Call(argc, argv);
|
||||
} else {
|
||||
Local<Value> err = NanError(pcsc_stringify_error(ar->result));
|
||||
Local<Value> err = NanError(error_msg("SCardListReaders", ar->result).c_str());
|
||||
// Prepare the parameters for the callback function.
|
||||
const unsigned argc = 1;
|
||||
Handle<Value> argv[argc] = { err };
|
||||
|
||||
Reference in New Issue
Block a user