File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change 11import fs from "fs" ;
2+ import { ConfigurationError } from "@pipedream/platform" ;
23
34function normalizeFilePath ( path ) {
45 return path . startsWith ( "/tmp/" )
@@ -24,8 +25,22 @@ function downloadToTmp(response, filename) {
2425 ] ;
2526}
2627
28+ function handleErrorMessage ( error ) {
29+ let errorMessage = error . name ;
30+ if ( error . response && error . response . data ) {
31+ const text = Buffer . from ( error . response . data ) . toString ( "utf-8" ) ;
32+ try {
33+ errorMessage = JSON . stringify ( JSON . parse ( text ) ) ;
34+ } catch ( parseErr ) {
35+ errorMessage = text ;
36+ }
37+ }
38+ throw new ConfigurationError ( `${ errorMessage } ` ) ;
39+ }
40+
2741export default {
2842 normalizeFilePath,
2943 checkForExtension,
3044 downloadToTmp,
45+ handleErrorMessage,
3146} ;
Original file line number Diff line number Diff line change 11import { axios } from "@pipedream/platform" ;
2+ import utils from "./common/utils.mjs" ;
23
34export default {
45 type : "app" ,
@@ -19,18 +20,22 @@ export default {
1920 _baseUrl ( ) {
2021 return "https://api.pdf4me.com/api/v2" ;
2122 } ,
22- _makeRequest ( {
23+ async _makeRequest ( {
2324 $ = this ,
2425 path = "/" ,
2526 ...otherOpts
2627 } ) {
27- return axios ( $ , {
28- ...otherOpts ,
29- url : `${ this . _baseUrl ( ) } ${ path } ` ,
30- headers : {
31- authorization : this . $auth . api_key ,
32- } ,
33- } ) ;
28+ try {
29+ return await axios ( $ , {
30+ ...otherOpts ,
31+ url : `${ this . _baseUrl ( ) } ${ path } ` ,
32+ headers : {
33+ authorization : this . $auth . api_key ,
34+ } ,
35+ } ) ;
36+ } catch ( error ) {
37+ utils . handleErrorMessage ( error ) ;
38+ }
3439 } ,
3540 convertToPdf ( opts = { } ) {
3641 return this . _makeRequest ( {
You can’t perform that action at this time.
0 commit comments