How to fix DOMException Decoding Email Message - gmail-api

I am using the GMail API to retrieve messages. The messages are machine generated, so follow a similar format.
Although most of the messages are fine, I am getting a DOMException using atob to decode the message body for a subset of the messages.
I think I've narrowed it down to messages that have a section in it that looks like:
--------------------- Sudo (secure-log) Begin ------------------------
jeremy => root
--------------
/usr/bin/docker - 5 Time(s).
---------------------- Sudo (secure-log) End -------------------------
Specifically I think that the problem happens because of the =>.
The error is:
Error parsing DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
Code fragment:
gapi.client.gmail.users.threads.get({
userId: 'me',
id: thread.id
})
.then(function(response){
var
content,
message = response.result.messages[0],
rawContent = message.payload.body.data;
try{
content = atob(rawContent);
}

This thread helped me Decode URL Safe Base64 in JavaScript (browser side)
rawContent = rawContent.replace(/_/g, '/').replace(/-/g, '+');
Fixed it up.

Related

Problem with sendFile method and CDN Services

It seems the service its returning 400 and Error when parsing request output when the files are kinda big (Well not at all, because i'm trying to upload a 505kb .zip and its returning me an error), any kind of solution about this? Seems to be a random stuff because i upload a .pdf with a size of lets say 244KB and it returns error and then i try to upload a pdf with a size of 300kb and it goes fine, seems the CDN endpoint is having a strange behaviour, its also me happening with the images but not with the same frequency as the files.
Anyone have any kind of fix for this or idea why its happening?
I tried used postman and nodejs code and the results are always the same
try {
const response = await channel.sendFile(fs.createReadStream('file.pdf'),'file.pdf');
console.log(response);
} catch(e) {
console.log(e)
}
}
The process is returning the following
{ FetchError: invalid json response body at https://chat-us-east-1.stream-io-api.com/channels/messaging/XXXXXXX/file?api_key=XXXXXX reason: Unexpected token E in JSON at position 0
at /Users/user/Desktop/react-stream-chat-nodejs/node_modules/node-fetch/lib/index.js:272:32
at process._tickCallback (internal/process/next_tick.js:68:7)
message:
'invalid json response body at https://chat-us-east-1.stream-io-api.com/channels/messaging/XXXXXX/file?api_key=XXXXXX reason: Unexpected token E in JSON at position 0',
type: 'invalid-json' }

CodenameOne - how to catch HTTP 404 error using Terse REST API

How can I catch an HTTP 404 error using the Terse REST API in CodenameOne? At the moment the default error handler gets this but I would like to display my own message instead. The code I am using is fine if the accountNo exists and I can deal with the resulting JSON, but if not I get the standard error handler displaying the 404 error:
Response<Map> jsonData = Rest.get( URL + "lookup").
jsonContent().
queryParam("account",accountNo).
getAsJsonMap();
This seems to be a mistake in that version of the method. It should fail silently without a UI Dialog. We'll fix it for the next update.
Notice that jsonData should have the error response code within it as jsonData.getResponseCode().

Thunderbird Lightning caldav sync doesn't show any data/events

when i try to synchronize my caldav server implementation with Thunderbird 45.4.0 and Lightning 4.7.4 (one particular calendar collection) it doesnt show any data or events in the calendar though the last call of the sequence provided the data.
In the Thunderbird error log i can see one error:
Zeitstempel: 07.11.16, 14:21:12
Fehler: [calCachedCalendar] replay action failed: null,
uri=http://127.0.0.1:8003/sap/sports/webdav/appsvc/webdav/services/
server.xsjs/cal/_D043133/, result=2147500037, op=[xpconnect wrapped
calIOperation]
Quelldatei:
file:///Users/d043133/Library/Thunderbird/Profiles/hfbvuk9f.default/
extensions/%7Be2fda1a4-762b-4020-b5ad-a41df1933103%7D/calendar-
js/calCachedCalendar.js
Zeile: 327
the call sequence is as follows (detailed content via gist-links):
Propfind Request - Response
Options Request - Response
Propfind Request - Response
Report Request - Response - Response Raw
The synchronization with other clients like macOS-calendar and ios-calendar works in principle and shows the data. Does anyone has a clue what is going wrong here?
Not sure whether that is the cause but I can see two incorrect things:
a) Your <href/> property has trailing spaces:
<d:href>/sap/sports/webdav/appsvc/webdav/services/server.xsjs/cal/_D043133/EVENT%3A070768ba5dd78ff15458f1985cdaabb1.ics
</d:href>
b) your ORGANIZER property is not a valid URI
ORGANIZER:_D043133
i was able to find the cause of the above issue by debugging Thunderbird as propsed by Philipp. The Report Response has http status code 200, but as it is a multistatus response Thunderbird/Lightning expects status code 207 ;-)
Thanks for the hints!

Can't get any response back while calling service through frisbyJS

The code I am using is:
var frisby = require('frisby');
frisby.create('Get paf data')
.get('https://services.....')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.toss();
The error I get while running it from CLI using
jasmine-node EndpointTest_spec.js
The error I get is:
Error: Expected 500 to equal 200
Error: Header 'content-type' not present in HTTP response
So do I need to first load my website and call services through my application and then run frisby ?
But then it defeats the purpose of just making a quick check for all the endpoints used in application without running it.
You are calling request with https:// which may be secure server so use
{ strictSSL: false} in your get method .get('https://services.....',{ strictSSL: false}). It will solve your problem.
var frisby = require('frisby');
frisby.create('Get paf data')
.get('https://services.....',{ strictSSL: false})
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.toss();

How to get instance of current message bein processed in cxf?

I want to get the ID of the Inbound message in my implemented service end point which has following parameters available:
Custom JAXB Request
#Context HttpServletRequest
e.g. From below inbound message i want to retrieve ID: 1 in my service endpoint.
INFO: Inbound Message
ID: 1
Address:
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/xml
Headers:
Payload:
Can anyone please tell me if there is a way to get that ID ?
You can get the current CXF Message using PhaseInterceptorChain.getCurrentMessage(). The logging ID used by the logging interceptors is stored in the Message Map, and can be retrieved with its key, e.g.
String loggingId = (String) PhaseInterceptorChain.getCurrentMessage().get(LoggingMessage.ID_KEY);

Resources