Skip to content

Commit

Permalink
fix: Add exception handling for JSON.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Sep 10, 2021
1 parent ebc8f87 commit bb6c7d0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/serializers/serializer-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class SerializerImpl implements Serializer {
deserialize<T = Record<string, unknown>>(type: MimeType, data: string): T {
switch (type) {
case 'application/json':
return transformKeys(JSON.parse(data), camelCase);
try {
return transformKeys(JSON.parse(data), camelCase);
} catch {
return undefined as unknown as T;
}
default:
throw new Error(`Unknown content type ${type}, ${data}`);
}
Expand Down

0 comments on commit bb6c7d0

Please sign in to comment.