Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 61a243c

Browse files
committed
Add check if a collab is actually just a rant
1 parent 084ae0d commit 61a243c

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/com/scorpiac/javarant/Collab.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.gson.JsonArray;
44
import com.google.gson.JsonObject;
55
import com.scorpiac.javarant.exceptions.NoSuchRantException;
6+
import com.scorpiac.javarant.exceptions.NotACollabException;
67

78
public class Collab extends Rant {
89
private String projectType;
@@ -42,6 +43,10 @@ public static Collab byId(int id) {
4243
}
4344

4445
static Collab fromJson(JsonObject json) {
46+
// Check if the rant is also a collab.
47+
if (json.has("id") && !json.has("c_type_long"))
48+
throw new NotACollabException(json.get("id").getAsInt());
49+
4550
return new Collab(
4651
json.get("id").getAsInt(),
4752
User.fromJson(json),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.scorpiac.javarant.exceptions;
2+
3+
public class NotACollabException extends RuntimeException {
4+
/**
5+
* Create a new exception for a rant that is not a collab.
6+
*
7+
* @param id The id of the rant.
8+
*/
9+
public NotACollabException(int id) {
10+
super("Rant with id " + id + " is not a collab.");
11+
}
12+
}

0 commit comments

Comments
 (0)