web stats
Send Error Message from API (PHP) to MIRTH - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2015, 08:14 PM
henriquetomaz henriquetomaz is offline
OBX.1 Kenobi
 
Join Date: Dec 2014
Posts: 45
henriquetomaz is on a distinguished road
Unhappy Send Error Message from API (PHP) to MIRTH

Hi,

I looked for this solution here in the Mirth Community but I didn't find any clear answer for this.

My web application (I am using cakephp 1.3) receives parameters by HTTP POST method from MIRTH. One of these parameters is a path of a file that I want to copy locally. Everything is working perfectly, however, I want to send an Error Message to Mirth when copying this file fails.

I want to print the error message ("Document not copied.") and I want it to be marked in MIRTH dashboard as an error.

I am using : throw new Exception('Document not copied.'); "

It marked an error on MIRTH Dashboard but didn't print my error message properly.

Thanks for your help

Bellow is may code for this:

// 6. save PDF file
$retCopy = $this->Document->copyPdf($id, $rgh, $sourcePath, $system);
if(!empty($retCopy)) {
echo "Sucessfully copied: $retornoCopy \n";
}else{
throw new Exception('Document not copied.');
}
}
}
Reply With Quote
  #2  
Old 05-06-2015, 06:35 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

I'm not sure how PHP handles exceptions like that, but you need to make sure the message of the exception is actually being sent back as the response payload. I'm guessing an error response code (>= 400) is already being sent back, because you say the message is erroring out in Mirth Connect. Though I wonder if it's just closing the connection and causing an error that way.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 05-06-2015, 07:09 AM
henriquetomaz henriquetomaz is offline
OBX.1 Kenobi
 
Join Date: Dec 2014
Posts: 45
henriquetomaz is on a distinguished road
Default

Hi Narupley,

Yes, you are right. The message is erroring out in Mith, however I'm not getting the error message on the response payload.

Anyways; thanks for your help.



Status: ERROR: Received error response from HTTP server.

Response (html error):

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>H2TC | Versão 2.4.4</title>
<link rel="icon" href="/h2tc/favicon_acccc2.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/h2tc/favicon_acccc2.ico" type="image/x-icon" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="/h2tc/css/folha_base.css?1424455742" /> <link rel="stylesheet" type="text/css" href="/h2tc/css/h2tc.css?1426797090" />
<link rel="stylesheet" type="text/css" href="/h2tc/css/folha_oliva.css?1424455742" id="estilo_pagina" import="import" />
<script type="text/javascript" src="/h2tc/js/menu.js?1424455743"></script> <script type="text/javascript" src="/h2tc/js/outerHTML.js?1424455762"></script> <script type="text/javascript" src="/h2tc/js/swfobject.js?1424455762"></script> <!-- EXTJS -->
<script type="text/javascript" src="/h2tc/js/ext-4.1.1a/bootstrap.js?1424455746"></script> <script type="text/javascript" src="/h2tc/js/ext-4.1.1a/examples/ux/data/PagingMemoryProxy.js?1424455760"></script>
<!-- import scripts to detect different types of browsers -->
<script type="text/javascript" src="/h2tc/js/bowser-master/bowser.js?1426797091"></script><script type="text/javascript" src="/h2tc/js/bowser-master/bowser.min.js?1426797091"></script>
<script type='text/javascript'>
// para construcao de URLs no javascript
function Cakehtml( )
{
this.placeholder = '{__path__}';
this.base_url = "/h2tc/{__path__}"

this.url = function (path)
{
return this.base_url.replace(this.placeholder, path)
}
}
cakehtml = new Cakehtml();
// use cakehtml.url( '/controller/method/par1...' ) para obter a url

</script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-1234-1', {'cookieDomain': 'intranet.cipe.accamargo.org.br', 'siteSpeedSampleRate': 100}, {'cookiePath': '/h2tc/'});
ga('require', 'linkid', 'linkid.js');
//ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
</head>

<body marginheight="0" marginwidth="0">

<!-- menu superior -->
<div class='barra_superior' style='position: relative'>
<div style="float:left; position:relative; top:8px; left:5px; width:300px; border:0px solid #000; font-weight: bold;"><a href="/h2tc/init/login">Não conectado</a> </div>


<div style="float:right;">
<div style="margin-top:7px; right: 15px; margin-right:20px; text-align:center;">
<a href="javascript:var x=menuS('op1');" class="link"><div style='float:left;'><img src="/h2tc/img/flag_pt_BR.UTF-8.jpg?1424455742" border="0" class="menu_Linguas" alt="" /></div></a></div>
<div id='op1' style="display:none;right:0px" class='menu_sub_opcao'><a href="/h2tc/init/changeLanguage/pt_BR.UTF-8" style="display:block" class="link"><div style='float:left;'><img src="/h2tc/img/flag_pt_BR.UTF-8.jpg?1424455742" border="0" class="menu_pt_BR.UTF-8" alt="" /></div></a><a href="/h2tc/init/changeLanguage/en_US.UTF-8" style="display:block" class="link"><div style='float:left;'><img src="/h2tc/img/flag_en_US.UTF-8.jpg?1424455742" border="0" class="menu_en_US.UTF-8" alt="" /></div></a></div> </div>
</div>

<div>
</div>

<!-- fim do menu superior -->
<div class='miolo_site' id='content'>

<script type="text/javascript">
if (Ext.get('flashMessage'))
setTimeout("Ext.get('flashMessage').hide()", 2500);
</script>

<h2>Fatal Error</h2>
<p class="error">
<strong>Error: </strong>
Class 'Response' not found <br>

<strong>File: </strong>
/home/users/henrique.silva/NetBeansProjects/h2tc/trunk/html/app/Controller/DocumentosController.php <br>

<strong>Line: </strong>
345</p>
<p class="notice">
<strong>Notice: </strong>
If you want to customize this error message, create app/View/Errors/fatal_error.ctp</p>
<!-- langt_BR.UTF-8 -->
</div>
</body>
</html>
Reply With Quote
  #4  
Old 05-06-2015, 07:37 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,116
narupley is on a distinguished road
Default

Yeah, looks like the POST is returning the entire HTML page. That's not exactly uncommon, because that's usually what's supposed to happen in browsers. But Mirth Connect is not a browser. If you were expecting it to automatically render the HTML and run JavaScript that was returned as the POST response, it will definitely not do that. So it sounds like you haven't set your server up correctly... it should have an endpoint to POST data to, that only returns the information you want, not an entire web page.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
Reply

Tags
cakephp, php, sent error message

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:09 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation