Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smart_hotel_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宏
smart_hotel_app
Commits
a7c9b9f7
Commit
a7c9b9f7
authored
Jun 11, 2026
by
张宏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2
parent
b875193d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
33 deletions
+47
-33
error_interceptor.dart
lib/utils/http/interceptors/error_interceptor.dart
+10
-8
request_interceptor.dart
lib/utils/http/interceptors/request_interceptor.dart
+10
-8
response_interceptor.dart
lib/utils/http/interceptors/response_interceptor.dart
+7
-5
logger.dart
lib/utils/logger.dart
+20
-12
No files found.
lib/utils/http/interceptors/error_interceptor.dart
View file @
a7c9b9f7
import
'dart:io'
;
import
'package:dio/dio.dart'
;
import
'../../logger.dart'
;
import
'../../event_bus.dart'
;
import
'../exceptions/app_exception.dart'
;
import
'../exceptions/business_exception.dart'
;
...
...
@@ -126,15 +127,15 @@ class ErrorInterceptor extends Interceptor {
}
void
_printErrorLog
(
DioException
err
,
String
uuid
,
AppException
exception
)
{
print
(
'========== Error START =========='
);
print
(
'UUID:
$uuid
'
);
print
(
'Error Type:
${err.type}
'
);
print
(
'Error Message:
${err.message}
'
);
print
(
'Exception:
$exception
'
);
Log
.
error
(
'========== Error START =========='
);
Log
.
error
(
'UUID:
$uuid
'
);
Log
.
error
(
'Error Type:
${err.type}
'
);
Log
.
error
(
'Error Message:
${err.message}
'
);
Log
.
error
(
'Exception:
$exception
'
);
if
(
err
.
response
!=
null
)
{
print
(
'Status Code:
${err.response?.statusCode}
'
);
print
(
'Response Data:
${err.response?.data}
'
);
Log
.
error
(
'Status Code:
${err.response?.statusCode}
'
);
Log
.
error
(
'Response Data:
${err.response?.data}
'
);
}
print
(
'========== Error END =========='
);
Log
.
error
(
'========== Error END =========='
);
}
}
\ No newline at end of file
lib/utils/http/interceptors/request_interceptor.dart
View file @
a7c9b9f7
import
'package:dio/dio.dart'
;
import
'../../logger.dart'
;
import
'../../storage/storage_service.dart'
;
class
RequestInterceptor
extends
Interceptor
{
...
...
@@ -45,17 +46,17 @@ class RequestInterceptor extends Interceptor {
}
void
_printRequestLog
(
RequestOptions
options
,
String
uuid
)
{
print
(
'==================== Request START ======================
'
);
print
(
'UUID:
$uuid
'
);
print
(
'Method:
${options.method
}
'
);
print
(
'URL:
${options.uri}
'
);
print
(
'Headers:
${options.headers}
'
);
Log
.
info
(
'********************** Request START **********************
'
);
Log
.
info
(
'UUID:
$uuid
'
);
Log
.
info
(
'Method:
${options.method}
URL:
${options.uri
}
'
);
// Log.info
('URL: ${options.uri}');
Log
.
info
(
'Headers:
${options.headers}
'
);
if
(
options
.
data
!=
null
)
{
print
(
'Data
:
${options.data}
'
);
Log
.
info
(
'POST入参
:
${options.data}
'
);
}
if
(
options
.
queryParameters
.
isNotEmpty
)
{
print
(
'Params
:
${options.queryParameters}
'
);
Log
.
info
(
'URL入参
:
${options.queryParameters}
'
);
}
print
(
'==================== Request END ======================
'
);
Log
.
info
(
'********************** Request END **********************
'
);
}
}
\ No newline at end of file
lib/utils/http/interceptors/response_interceptor.dart
View file @
a7c9b9f7
import
'package:dio/dio.dart'
;
import
'../../logger.dart'
;
class
ResponseInterceptor
extends
Interceptor
{
@override
...
...
@@ -11,10 +12,10 @@ class ResponseInterceptor extends Interceptor {
}
void
_printResponseLog
(
Response
response
,
String
uuid
)
{
print
(
'
==================== Response START ======================'
);
print
(
'UUID:
$uuid
'
);
print
(
'Status Code:
${response.statusCode}
'
);
print
(
'Data:
${response.data}
'
);
print
(
'
==================== Response END ======================'
);
Log
.
warn
(
'==
==================== Response START ======================'
);
Log
.
warn
(
'UUID:
$uuid
'
);
Log
.
warn
(
'Status Code:
${response.statusCode}
'
);
Log
.
warn
(
'Data:
${response.data}
'
);
Log
.
warn
(
'==
==================== Response END ======================'
);
}
}
\ No newline at end of file
lib/utils/logger.dart
View file @
a7c9b9f7
import
'package:logger/logger.dart'
as
pkg
;
class
Log
{
static
final
pkg
.
Logger
_logger
=
pkg
.
Logger
(
printer:
pkg
.
PrettyPrinter
(
methodCount:
0
,
errorMethodCount:
5
,
lineLength:
90
,
colors:
true
,
printEmojis:
true
,
),
);
static
void
info
(
String
message
)
{
// ignore: avoid_print
print
(
'[INFO]
$message
'
);
_logger
.
i
(
message
);
}
static
void
warn
(
String
message
)
{
_logger
.
w
(
message
);
}
static
void
error
(
String
message
,
[
dynamic
error
])
{
// ignore: avoid_print
print
(
'[ERROR]
$message
'
);
if
(
error
!=
null
)
{
// ignore: avoid_print
print
(
'[ERROR]
$error
'
);
}
_logger
.
e
(
message
,
error:
error
);
}
static
void
request
(
String
message
)
{
// ignore: avoid_print
print
(
'[REQUEST]
$message
'
);
_logger
.
i
(
'[REQUEST]
$message
'
);
}
static
void
response
(
String
message
)
{
// ignore: avoid_print
print
(
'[RESPONSE]
$message
'
);
_logger
.
i
(
'[RESPONSE]
$message
'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment