classifyHttpError function

ClassifiedError classifyHttpError(
  1. Object error
)

Classify an HTTP error into a category.

Implementation

ClassifiedError classifyHttpError(Object error) {
  final msg = error.toString().toLowerCase();
  if (msg.contains('401') ||
      msg.contains('403') ||
      msg.contains('unauthorized')) {
    return ClassifiedError(
      kind: 'auth',
      message: 'Not authorized for settings sync',
    );
  }
  if (msg.contains('timeout')) {
    return ClassifiedError(
      kind: 'timeout',
      message: 'Settings sync request timeout',
    );
  }
  if (msg.contains('socket') ||
      msg.contains('connection') ||
      msg.contains('network')) {
    return ClassifiedError(
      kind: 'network',
      message: 'Cannot connect to server',
    );
  }
  return ClassifiedError(kind: 'other', message: error.toString());
}