Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
오윤석
2020-11-07 05:58:32 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
be670e3f5dc66fa849818b420e28fb715aa4f611
be670e3f
1 parent
a797f66b
에러 대응을 위해 http status 추가
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
22 deletions
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
app/src/main/java/com/sunnni/smartdoorlock/api/ApiResult.java
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
View file @
be670e3
...
...
@@ -63,8 +63,13 @@ public class Api {
os
.
close
();
}
int
status
=
conn
.
getResponseCode
();
Log
.
d
(
"status"
,
String
.
valueOf
(
status
));
InputStream
is
=
conn
.
getErrorStream
();
if
(
is
==
null
)
is
=
conn
.
getInputStream
();
StringBuilder
builder
=
new
StringBuilder
();
InputStream
is
=
conn
.
getInputStream
();
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
));
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
...
...
@@ -72,13 +77,12 @@ public class Api {
}
Log
.
d
(
"http result"
,
builder
.
toString
());
JsonElement
jsonElement
=
JsonParser
.
parseString
(
builder
.
toString
());
apiResult
=
new
ApiResult
(
true
,
jsonElement
);
apiResult
=
new
ApiResult
(
status
<
300
,
status
,
jsonElement
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
apiResult
=
new
ApiResult
(
false
,
e
.
getMessage
()
);
apiResult
=
new
ApiResult
(
false
);
}
final
ApiResult
finalApiResult
=
apiResult
;
...
...
app/src/main/java/com/sunnni/smartdoorlock/api/ApiResult.java
View file @
be670e3
package
com
.
sunnni
.
smartdoorlock
.
api
;
public
class
ApiResult
{
public
String
getError
()
{
return
this
.
error
;
}
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
public
boolean
isError
()
{
return
this
.
error
!=
null
;
public
class
ApiResult
{
public
boolean
isSuccess
()
{
return
this
.
success
;
}
public
Object
getData
()
{
return
this
.
data
;
}
public
void
setError
(
String
error
)
{
this
.
error
=
error
;
public
int
getStatus
(
)
{
return
this
.
status
;
}
public
void
setData
(
Object
data
)
{
this
.
data
=
data
;
}
public
ApiResult
(
boolean
result
,
Object
obj
)
{
if
(
result
)
{
public
ApiResult
(
boolean
success
,
int
status
,
JsonElement
obj
)
{
this
.
success
=
success
;
this
.
data
=
obj
;
}
else
{
this
.
error
=
(
String
)
obj
;
this
.
status
=
status
;
}
public
ApiResult
(
boolean
success
)
{
this
.
success
=
success
;
this
.
data
=
null
;
this
.
status
=
999
;
}
private
String
error
;
private
Object
data
;
private
boolean
success
;
private
JsonElement
data
;
private
int
status
;
}
...
...
Please
register
or
login
to post a comment